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