mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge branch 'cchurch-devel' into devel
This commit is contained in:
commit
21f8c0bc96
4 changed files with 133 additions and 2 deletions
|
@ -38,6 +38,8 @@ class ActionModule(object):
|
||||||
# the group_by module does not need to pay attention to check mode.
|
# the group_by module does not need to pay attention to check mode.
|
||||||
# it always runs.
|
# it always runs.
|
||||||
|
|
||||||
|
# module_args and complex_args have already been templated for the first host.
|
||||||
|
# Use them here only to check that a key argument is provided.
|
||||||
args = {}
|
args = {}
|
||||||
if complex_args:
|
if complex_args:
|
||||||
args.update(complex_args)
|
args.update(complex_args)
|
||||||
|
@ -68,7 +70,16 @@ class ActionModule(object):
|
||||||
break
|
break
|
||||||
if next_host:
|
if next_host:
|
||||||
continue
|
continue
|
||||||
group_name = template.template(self.runner.basedir, args['key'], data)
|
|
||||||
|
# Template original module_args and complex_args from runner for each host.
|
||||||
|
host_module_args = template.template(self.runner.basedir, self.runner.module_args, data)
|
||||||
|
host_complex_args = template.template(self.runner.basedir, self.runner.complex_args, data)
|
||||||
|
host_args = {}
|
||||||
|
if host_complex_args:
|
||||||
|
host_args.update(host_complex_args)
|
||||||
|
host_args.update(parse_kv(host_module_args))
|
||||||
|
|
||||||
|
group_name = host_args['key']
|
||||||
group_name = group_name.replace(' ','-')
|
group_name = group_name.replace(' ','-')
|
||||||
if group_name not in groups:
|
if group_name not in groups:
|
||||||
groups[group_name] = []
|
groups[group_name] = []
|
||||||
|
|
|
@ -14,7 +14,7 @@ else
|
||||||
CREDENTIALS_ARG =
|
CREDENTIALS_ARG =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: non_destructive destructive check_mode test_hash test_handlers
|
all: non_destructive destructive check_mode test_hash test_handlers test_group_by
|
||||||
|
|
||||||
non_destructive:
|
non_destructive:
|
||||||
ansible-playbook non_destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
ansible-playbook non_destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||||
|
@ -25,6 +25,9 @@ destructive:
|
||||||
check_mode:
|
check_mode:
|
||||||
ansible-playbook check_mode.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v --check $(TEST_FLAGS)
|
ansible-playbook check_mode.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v --check $(TEST_FLAGS)
|
||||||
|
|
||||||
|
test_group_by:
|
||||||
|
ansible-playbook test_group_by.yml -i inventory.group_by -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||||
|
|
||||||
test_handlers:
|
test_handlers:
|
||||||
ansible-playbook test_handlers.yml -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
ansible-playbook test_handlers.yml -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||||
|
|
||||||
|
|
6
test/integration/inventory.group_by
Normal file
6
test/integration/inventory.group_by
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[lamini]
|
||||||
|
alpaca genus=vicugna
|
||||||
|
llama genus=lama
|
||||||
|
|
||||||
|
[lamini:vars]
|
||||||
|
ansible_connection=local
|
111
test/integration/test_group_by.yml
Normal file
111
test/integration/test_group_by.yml
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
- hosts: lamini
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: group by genus
|
||||||
|
group_by: key={{ genus }}
|
||||||
|
- name: group by first three letters of genus with key in quotes
|
||||||
|
group_by: key="{{ genus | truncate(3, true, '') }}"
|
||||||
|
- name: group by first two letters of genus with key not in quotes
|
||||||
|
group_by: key={{ genus | truncate(2, true, '') }}
|
||||||
|
- name: group by genus in uppercase using complex args
|
||||||
|
group_by: { key: "{{ genus | upper() }}" }
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- hosts: '{{genus'
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: no hosts should match this group
|
||||||
|
fail: msg="should never get here"
|
||||||
|
|
||||||
|
- hosts: alpaca
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: check that alpaca matched all four groups
|
||||||
|
assert: { that: ["genus_vicugna", "genus_vic", "genus_vi", "genus_VICUGNA"] }
|
||||||
|
|
||||||
|
- hosts: llama
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: check that llama matched all four groups
|
||||||
|
assert: { that: ["genus_lama", "genus_lam", "genus_la", "genus_LAMA"] }
|
Loading…
Reference in a new issue