Small change to previous patch, make ranges of hosts inclusive.
parent
416b8d59a9
commit
8fa4dc3920
|
@ -45,6 +45,7 @@ Ansible Changes By Release
|
||||||
* minor caching logic added to inventory to reduce hammering of inventory scripts.
|
* minor caching logic added to inventory to reduce hammering of inventory scripts.
|
||||||
* ./hacking/test-module now supports options like ansible takes and has a debugger mode
|
* ./hacking/test-module now supports options like ansible takes and has a debugger mode
|
||||||
* playbook is now colorized, set ANSIBLE_NOCOLOR=1 if you do not like this, does not colorize if not a TTY
|
* playbook is now colorized, set ANSIBLE_NOCOLOR=1 if you do not like this, does not colorize if not a TTY
|
||||||
|
* support ranges of hosts in the host file
|
||||||
|
|
||||||
0.5 "Amsterdam" ------- July 04, 2012
|
0.5 "Amsterdam" ------- July 04, 2012
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
.\" Title: ansible-playbook
|
.\" Title: ansible-playbook
|
||||||
.\" Author: [see the "AUTHOR" section]
|
.\" Author: [see the "AUTHOR" section]
|
||||||
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
|
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
|
||||||
.\" Date: 07/04/2012
|
.\" Date: 07/24/2012
|
||||||
.\" Manual: System administration commands
|
.\" Manual: System administration commands
|
||||||
.\" Source: Ansible 0.6
|
.\" Source: Ansible 0.6
|
||||||
.\" Language: English
|
.\" Language: English
|
||||||
.\"
|
.\"
|
||||||
.TH "ANSIBLE\-PLAYBOOK" "1" "07/04/2012" "Ansible 0\&.6" "System administration commands"
|
.TH "ANSIBLE\-PLAYBOOK" "1" "07/24/2012" "Ansible 0\&.6" "System administration commands"
|
||||||
.\" -----------------------------------------------------------------
|
.\" -----------------------------------------------------------------
|
||||||
.\" * set default formatting
|
.\" * set default formatting
|
||||||
.\" -----------------------------------------------------------------
|
.\" -----------------------------------------------------------------
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
.\" Title: ansible
|
.\" Title: ansible
|
||||||
.\" Author: [see the "AUTHOR" section]
|
.\" Author: [see the "AUTHOR" section]
|
||||||
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
|
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
|
||||||
.\" Date: 07/04/2012
|
.\" Date: 07/24/2012
|
||||||
.\" Manual: System administration commands
|
.\" Manual: System administration commands
|
||||||
.\" Source: Ansible 0.6
|
.\" Source: Ansible 0.6
|
||||||
.\" Language: English
|
.\" Language: English
|
||||||
.\"
|
.\"
|
||||||
.TH "ANSIBLE" "1" "07/04/2012" "Ansible 0\&.6" "System administration commands"
|
.TH "ANSIBLE" "1" "07/24/2012" "Ansible 0\&.6" "System administration commands"
|
||||||
.\" -----------------------------------------------------------------
|
.\" -----------------------------------------------------------------
|
||||||
.\" * set default formatting
|
.\" * set default formatting
|
||||||
.\" -----------------------------------------------------------------
|
.\" -----------------------------------------------------------------
|
||||||
|
@ -140,19 +140,9 @@ Connection type to use\&. Possible options are
|
||||||
.RE
|
.RE
|
||||||
.SH "INVENTORY"
|
.SH "INVENTORY"
|
||||||
.sp
|
.sp
|
||||||
Ansible stores the hosts it can potentially operate on in an inventory
|
Ansible stores the hosts it can potentially operate on in an inventory file\&. The syntax is one host per line\&. Groups headers are allowed and are included on their own line, enclosed in square brackets that start the line\&.
|
||||||
file\&. The syntax is one host per line\&. Optionally, ansible can use a
|
.sp
|
||||||
line of the form base[beg:end]tail to define a set of hosts, where
|
Ranges of hosts are also supported\&. For more information and additional options, see the documentation on http://ansible\&.github\&.com/\&.
|
||||||
[beg:end] defines a numerical range. If 'beg' is left out, it
|
|
||||||
defaults to 0\&. An example: mail[1:6].example.com, where 'head'
|
|
||||||
is 'mail', 'beg' is 1, 'end' is 6, and 'tail' is '.example.com'\&. In
|
|
||||||
addition, 'beg' can be a a string padded with zero(s) to the left. If so
|
|
||||||
provided, it acts as a formatting hint during hostname expansion. The usage
|
|
||||||
must be confirmed by having an 'end' that has the same length as 'beg',
|
|
||||||
else an exception is raised. An example: mail[001:003].example.com is to be
|
|
||||||
expanded to mail001.example.com, mail002.example.com, and
|
|
||||||
mail003.example.com\&. Groups headers are allowed and are included on their
|
|
||||||
own line, enclosed in square brackets\&.
|
|
||||||
.SH "FILES"
|
.SH "FILES"
|
||||||
.sp
|
.sp
|
||||||
/etc/ansible/hosts \(em Default inventory file
|
/etc/ansible/hosts \(em Default inventory file
|
||||||
|
|
|
@ -31,7 +31,6 @@ A name of a group in the inventory file, a shell-like glob selecting
|
||||||
hosts in inventory file, or any combination of the two separated by
|
hosts in inventory file, or any combination of the two separated by
|
||||||
semicolons.
|
semicolons.
|
||||||
|
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
@ -112,7 +111,11 @@ INVENTORY
|
||||||
|
|
||||||
Ansible stores the hosts it can potentially operate on in an inventory
|
Ansible stores the hosts it can potentially operate on in an inventory
|
||||||
file. The syntax is one host per line. Groups headers are allowed and
|
file. The syntax is one host per line. Groups headers are allowed and
|
||||||
are included on their own line, enclosed in square brackets.
|
are included on their own line, enclosed in square brackets that
|
||||||
|
start the line.
|
||||||
|
|
||||||
|
Ranges of hosts are also supported. For more information and
|
||||||
|
additional options, see the documentation on http://ansible.github.com/.
|
||||||
|
|
||||||
FILES
|
FILES
|
||||||
-----
|
-----
|
||||||
|
|
|
@ -7,39 +7,38 @@
|
||||||
# - Groups of hosts are delimited by [header] elements
|
# - Groups of hosts are delimited by [header] elements
|
||||||
# - You can enter hostnames or ip addresses
|
# - You can enter hostnames or ip addresses
|
||||||
# - A hostname/ip can be a member of multiple groups
|
# - A hostname/ip can be a member of multiple groups
|
||||||
#
|
|
||||||
# Ex 1: Ungrouped hosts, specify before any group headers.
|
# Ex 1: Ungrouped hosts, specify before any group headers.
|
||||||
green.bikeshed.org
|
|
||||||
blue.bikeshed.org
|
green.example.com
|
||||||
red.bikeshed.org
|
blue.example.com
|
||||||
bikeshed.org
|
|
||||||
bastion.secure.bikeshed.org
|
|
||||||
192.168.100.1
|
192.168.100.1
|
||||||
192.168.100.10
|
192.168.100.10
|
||||||
# An example for host expansion that uses the default 'beg' and an 'end'
|
|
||||||
mail[:5].example.com
|
|
||||||
|
|
||||||
# Ex 2: A collection of hosts belonging to the 'webservers' group
|
# Ex 2: A collection of hosts belonging to the 'webservers' group
|
||||||
|
|
||||||
[webservers]
|
[webservers]
|
||||||
www01.bikeshed.org
|
alpha.example.org
|
||||||
www02.bikeshed.org
|
beta.example.org
|
||||||
wheel.colors.com
|
|
||||||
192.168.1.100
|
192.168.1.100
|
||||||
192.168.1.110
|
192.168.1.110
|
||||||
# Your personal website also runs a webserver:
|
|
||||||
myserver.com
|
# If you have multiple hosts following a pattern you can specify
|
||||||
# An example for host expansion that uses both a 'beg' and an 'end', with
|
# them like this:
|
||||||
# the 'beg' acting as a formatting hint during host name expansion
|
|
||||||
www[001:006].example.com
|
www[001:006].example.com
|
||||||
|
|
||||||
# Ex 3: A collection of database servers in the 'dbservers' group
|
# Ex 3: A collection of database servers in the 'dbservers' group
|
||||||
|
|
||||||
[dbservers]
|
[dbservers]
|
||||||
|
|
||||||
db01.intranet.mydomain.net
|
db01.intranet.mydomain.net
|
||||||
10.25.1.56
|
|
||||||
db02.intranet.mydomain.net
|
db02.intranet.mydomain.net
|
||||||
|
10.25.1.56
|
||||||
10.25.1.57
|
10.25.1.57
|
||||||
# Perhaps you serve a db off your personal server too:
|
|
||||||
myserver.com
|
# Here's another example of host ranges, this time there are no
|
||||||
# An example for host expansion that uses a regular 'beg' and a regular
|
# leading 0s:
|
||||||
# 'end'
|
|
||||||
db-[99:101]-node.example.com
|
db-[99:101]-node.example.com
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
'''
|
'''
|
||||||
This module is for enhancing ansible's inventory parsing capability such
|
This module is for enhancing ansible's inventory parsing capability such
|
||||||
that it can deal with hostnames specified using a simple pattern in the
|
that it can deal with hostnames specified using a simple pattern in the
|
||||||
|
@ -69,13 +70,13 @@ def expand_hostname_range(line = None):
|
||||||
(head, nrange, tail) = line.replace('[','|').replace(']','|').split('|')
|
(head, nrange, tail) = line.replace('[','|').replace(']','|').split('|')
|
||||||
bounds = nrange.split(":")
|
bounds = nrange.split(":")
|
||||||
if len(bounds) != 2:
|
if len(bounds) != 2:
|
||||||
raise ValueError("host range incorrectly specified!")
|
raise ValueError("host range incorrectly specified")
|
||||||
beg = bounds[0]
|
beg = bounds[0]
|
||||||
end = bounds[1]
|
end = bounds[1]
|
||||||
if not beg:
|
if not beg:
|
||||||
beg = "0"
|
beg = "0"
|
||||||
if not end:
|
if not end:
|
||||||
raise ValueError("host range end value missing!")
|
raise ValueError("host range end value missing")
|
||||||
if beg[0] == '0' and len(beg) > 1:
|
if beg[0] == '0' and len(beg) > 1:
|
||||||
rlen = len(beg) # range length formatting hint
|
rlen = len(beg) # range length formatting hint
|
||||||
else:
|
else:
|
||||||
|
@ -83,7 +84,7 @@ def expand_hostname_range(line = None):
|
||||||
if rlen > 1 and rlen != len(end):
|
if rlen > 1 and rlen != len(end):
|
||||||
raise ValueError("host range format incorrectly specified!")
|
raise ValueError("host range format incorrectly specified!")
|
||||||
|
|
||||||
for _ in range(int(beg), int(end)):
|
for _ in range(int(beg), int(end)+1):
|
||||||
if rlen:
|
if rlen:
|
||||||
rseq = str(_).zfill(rlen) # range sequence
|
rseq = str(_).zfill(rlen) # range sequence
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
jupiter
|
jupiter
|
||||||
saturn
|
saturn
|
||||||
thrudgelmir[:6]
|
thrudgelmir[:5]
|
||||||
|
|
||||||
[greek]
|
[greek]
|
||||||
zeus
|
zeus
|
||||||
hera:3000
|
hera:3000
|
||||||
poseidon
|
poseidon
|
||||||
cerberus[001:004]
|
cerberus[001:003]
|
||||||
cottus[99:101]
|
cottus[99:100]
|
||||||
|
|
||||||
[norse]
|
[norse]
|
||||||
thor
|
thor
|
||||||
|
|
Loading…
Reference in New Issue