1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# test code for the group_by module
# (c) 2014, Chris Church <cchurch@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Create overall groups
hosts: all
gather_facts: false
tasks:
- include_tasks: create_groups.yml
- name: Vicunga group validation
hosts: vicugna
gather_facts: false
tasks:
- name: verify that only the alpaca is in this group
assert: { that: "inventory_hostname == 'alpaca'" }
- name: set a fact to check that we ran this play
set_fact: genus_vicugna=true
- name: Lama group validation
hosts: lama
gather_facts: false
tasks:
- name: verify that only the llama is in this group
assert: { that: "inventory_hostname == 'llama'" }
- name: set a fact to check that we ran this play
set_fact: genus_lama=true
- name: Camelus group validation
hosts: camelus
gather_facts: false
tasks:
- name: verify that only the camel is in this group
assert: { that: "inventory_hostname == 'camel'" }
- name: set a fact to check that we ran this play
set_fact: genus_camelus=true
- name: Vic group validation
hosts: vic
gather_facts: false
tasks:
- name: verify that only the alpaca is in this group
assert: { that: "inventory_hostname == 'alpaca'" }
- name: set a fact to check that we ran this play
set_fact: genus_vic=true
- name: Lam group validation
hosts: lam
gather_facts: false
tasks:
- name: verify that only the llama is in this group
assert: { that: "inventory_hostname == 'llama'" }
- name: set a fact to check that we ran this play
set_fact: genus_lam=true
- name: Cam group validation
hosts: cam
gather_facts: false
tasks:
- name: verify that only the camel is in this group
assert: { that: "inventory_hostname == 'camel'" }
- name: set a fact to check that we ran this play
set_fact: genus_cam=true
- name: Vi group validation
hosts: vi
gather_facts: false
tasks:
- name: verify that only the alpaca is in this group
assert: { that: "inventory_hostname == 'alpaca'" }
- name: set a fact to check that we ran this play
set_fact: genus_vi=true
- name: La group validation
hosts: la
gather_facts: false
tasks:
- name: verify that only the llama is in this group
assert: { that: "inventory_hostname == 'llama'" }
- name: set a fact to check that we ran this play
set_fact: genus_la=true
- name: Ca group validation
hosts: ca
gather_facts: false
tasks:
- name: verify that only the camel is in this group
assert: { that: "inventory_hostname == 'camel'" }
- name: set a fact to check that we ran this play
set_fact: genus_ca=true
- name: VICUGNA group validation
hosts: VICUGNA
gather_facts: false
tasks:
- name: verify that only the alpaca is in this group
assert: { that: "inventory_hostname == 'alpaca'" }
- name: set a fact to check that we ran this play
set_fact: genus_VICUGNA=true
- name: LAMA group validation
hosts: LAMA
gather_facts: false
tasks:
- name: verify that only the llama is in this group
assert: { that: "inventory_hostname == 'llama'" }
- name: set a fact to check that we ran this play
set_fact: genus_LAMA=true
- name: CAMELUS group validation
hosts: CAMELUS
gather_facts: false
tasks:
- name: verify that only the camel is in this group
assert: { that: "inventory_hostname == 'camel'" }
- name: set a fact to check that we ran this play
set_fact: genus_CAMELUS=true
- name: alpaca validation of groups
hosts: alpaca
gather_facts: false
tasks:
- name: check that alpaca matched all four groups
assert: { that: ["genus_vicugna", "genus_vic", "genus_vi", "genus_VICUGNA"] }
- name: llama validation of groups
hosts: llama
gather_facts: false
tasks:
- name: check that llama matched all four groups
assert: { that: ["genus_lama", "genus_lam", "genus_la", "genus_LAMA"] }
- hosts: camel
gather_facts: false
tasks:
- name: check that camel matched all four groups
assert: { that: ["genus_camelus", "genus_cam", "genus_ca", "genus_CAMELUS"] }
- hosts: vicugna
gather_facts: false
tasks:
- name: check group_vars variable overrides for vicugna
assert: { that: ["uno == 1", "dos == 2", "tres == 'three'"] }
- hosts: lama
gather_facts: false
tasks:
- name: check group_vars variable overrides for lama
assert: { that: ["uno == 1", "dos == 2", "tres == 3"] }
- hosts: camelus
gather_facts: false
tasks:
- name: check group_vars variable overrides for camelus
assert: { that: ["uno == 1", "dos == 'two'", "tres == 3"] }
- name: Nested group validation
hosts: lama
gather_facts: false
tasks:
- name: group by genus with parent
group_by: key=vicugna-{{ genus }} parents=vicugna
- name: check group_vars variable overrides for vicugna-lama
assert: { that: ["uno == 1", "dos == 2", "tres == 'three'"] }
- name: group by genus with nonexistent parent
group_by:
key: "{{ genus }}"
parents:
- oxydactylus
- stenomylus
- name: check parent groups
assert: { that: ["'oxydactylus' in group_names", "'stenomylus' in group_names"] }
|