2014-05-07 02:30:37 +00:00
|
|
|
# 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/>.
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: Create overall groups
|
2015-07-27 11:38:34 +00:00
|
|
|
hosts: all
|
2014-05-07 02:30:37 +00:00
|
|
|
gather_facts: false
|
|
|
|
tasks:
|
2015-07-10 05:53:59 +00:00
|
|
|
- debug: var=genus
|
2014-05-07 02:30:37 +00:00
|
|
|
- name: group by genus
|
|
|
|
group_by: key={{ genus }}
|
2015-07-10 05:53:59 +00:00
|
|
|
|
2014-05-07 02:30:37 +00:00
|
|
|
- name: group by first three letters of genus with key in quotes
|
2017-01-09 22:54:43 +00:00
|
|
|
group_by: key="{{ genus[:3] }}"
|
2015-07-10 05:53:59 +00:00
|
|
|
|
2014-05-07 02:30:37 +00:00
|
|
|
- name: group by first two letters of genus with key not in quotes
|
2017-01-09 22:54:43 +00:00
|
|
|
group_by: key={{ genus[:2] }}
|
2015-07-10 05:53:59 +00:00
|
|
|
|
2014-05-07 02:30:37 +00:00
|
|
|
- name: group by genus in uppercase using complex args
|
|
|
|
group_by: { key: "{{ genus | upper() }}" }
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: Vicunga group validation
|
|
|
|
hosts: vicugna
|
2014-05-07 02:30:37 +00:00
|
|
|
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
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: Lama group validation
|
|
|
|
hosts: lama
|
2014-05-07 02:30:37 +00:00
|
|
|
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
|
|
|
|
|
2015-07-27 11:38:34 +00:00
|
|
|
- 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
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: Vic group validation
|
|
|
|
hosts: vic
|
2014-05-07 02:30:37 +00:00
|
|
|
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
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: Lam group validation
|
|
|
|
hosts: lam
|
2014-05-07 02:30:37 +00:00
|
|
|
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
|
|
|
|
|
2015-07-27 11:38:34 +00:00
|
|
|
- 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
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: Vi group validation
|
|
|
|
hosts: vi
|
2014-05-07 02:30:37 +00:00
|
|
|
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
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: La group validation
|
|
|
|
hosts: la
|
2014-05-07 02:30:37 +00:00
|
|
|
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
|
|
|
|
|
2015-07-27 11:38:34 +00:00
|
|
|
- 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
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: VICUGNA group validation
|
|
|
|
hosts: VICUGNA
|
2014-05-07 02:30:37 +00:00
|
|
|
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
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: LAMA group validation
|
|
|
|
hosts: LAMA
|
2014-05-07 02:30:37 +00:00
|
|
|
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
|
|
|
|
|
2015-07-27 11:38:34 +00:00
|
|
|
- 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
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: genus group validation (expect skipped)
|
|
|
|
hosts: 'genus'
|
2014-05-07 02:30:37 +00:00
|
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
|
|
- name: no hosts should match this group
|
|
|
|
fail: msg="should never get here"
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: alpaca validation of groups
|
|
|
|
hosts: alpaca
|
2014-05-07 02:30:37 +00:00
|
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
|
|
- name: check that alpaca matched all four groups
|
|
|
|
assert: { that: ["genus_vicugna", "genus_vic", "genus_vi", "genus_VICUGNA"] }
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
- name: llama validation of groups
|
|
|
|
hosts: llama
|
2014-05-07 02:30:37 +00:00
|
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
|
|
- name: check that llama matched all four groups
|
|
|
|
assert: { that: ["genus_lama", "genus_lam", "genus_la", "genus_LAMA"] }
|
2015-07-27 11:38:34 +00:00
|
|
|
|
|
|
|
- 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"] }
|