Skip to content

Commit 751134f

Browse files
bcocaacozine
authored andcommitted
Clearer examples of hosts.yml inventory (ansible#57999)
* Clearer examples of hosts.yml inventory
1 parent 8646b69 commit 751134f

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

examples/hosts.yaml

+35-24
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# - You can enter hostnames or IP addresses
1515
# - A hostname/IP can be a member of multiple groups
1616

17-
# Ex 1: Ungrouped hosts, put them in 'all' or 'ungrouped' group
17+
# Ex 1: Ungrouped hosts, put them in 'all' or 'ungrouped' group, defines 4 hosts, one with 2 variables
1818
##all:
1919
## hosts:
2020
## green.example.com:
@@ -24,35 +24,46 @@
2424
## 192.168.100.1:
2525
## 192.168.100.10:
2626

27-
# Ex 2: A collection of hosts belonging to the 'webservers' group
28-
## children:
29-
## webservers:
30-
## hosts:
31-
## alpha.example.org:
32-
## beta.example.org:
33-
## 192.168.1.100:
34-
## 192.168.1.110:
27+
# Ex 2: A collection of hosts belonging to the 'webservers' group, with shared group var
28+
##webservers:
29+
## hosts:
30+
## alpha.example.org:
31+
## beta.example.org:
32+
## 192.168.1.100:
33+
## 192.168.1.110:
34+
## vars:
35+
## http_port: 8080
3536

3637
# Ex 3: You can create hosts using ranges and add children groups and vars to a group
3738
# The child group can define anything you would normally add to a group.
38-
# webservers is added as a child group of testing. gamma.example.org is added
39-
# to the existing webservers group. All references to webservers will
40-
# get alpha.example.org, beta.example.org, gamma.example.org, 192.168.1.100
41-
# and 192.168.1.110. References to testing will get all of those hosts plus
42-
# any host matching www[001:006].example.com
43-
44-
## testing:
45-
## hosts:
46-
## www[001:006].example.com:
47-
## vars:
48-
## testing1: value1
49-
## children:
50-
## webservers:
51-
## hosts:
52-
## gamma.example.org:
39+
# Hosts in child groups inherit all variables from parent, parents include all hosts in child groups.
40+
# webservers is added as a child group of testing, so all gamma hosts (1-3) are added
41+
# to the 'webservers' group, including gamma3, which is defined in the tree of another parent group.
42+
# All references to webservers will get any hosts defined under webservers.
43+
# References to testing will get all of those hosts plus any host matching www[001:006].example.com
44+
45+
##webservers:
46+
## hosts:
47+
## gamma1.example.org:
48+
## gamma2.example.org:
49+
##testing:
50+
## hosts:
51+
## www[001:006].example.com:
52+
## vars:
53+
## testing1: value1
54+
## children:
55+
## webservers:
56+
##other:
57+
## children:
58+
## webservers:
59+
## gamma3.example.org
60+
61+
# From above, the testing group contains: gamma1.example.org gamma2.example.org gamma3.example.org www001.example.com www002.example.com www003.example.com www004.example.com www005.example.com www006.example.com
5362

5463
# Ex 4: all vars
5564
# keeping within 'all' group you can define common 'all' vars here with lowest precedence
5665

66+
67+
##all:
5768
## vars:
5869
## commontoall: thisvar

0 commit comments

Comments
 (0)