1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/lookup_merge_variables/test_all_hosts.yml
patchback[bot] 3e235f78d1
[PR #7999/0ded1109 backport][stable-8] feat(lookup/merge_variables): Add all hosts mode to collect configuration across multiple hosts (#8069)
feat(lookup/merge_variables): Add all hosts mode to collect configuration across multiple hosts (#7999)

* Add Feature to collect variables accross different hosts

* fix merging lists

* adjust unit tests

* lint fixes

* adjusting integration tests

* remove white spaces

* Update plugins/lookup/merge_variables.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/merge_variables.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/merge_variables.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* apply suggested changes to correctly handling the initial_value parameter, incl. additional test

* whitespace

---------

Co-authored-by: Alexander Petrenz <alexander.petrenz@posteo.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 0ded1109fe)

Co-authored-by: Alexander Petrenz <petrenz.a@gmail.com>
2024-03-09 12:42:22 +00:00

64 lines
2.8 KiB
YAML

---
# Copyright (c) 2020, Thales Netherlands
# Copyright (c) 2021, Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Test merge_variables lookup plugin (multiple hosts)
hosts: host0
gather_facts: false
tasks:
- name: Test merge dicts via all group
delegate_to: localhost
vars:
merged_dict: "{{ lookup('community.general.merge_variables', '__merge_dict_ex', pattern_type='suffix', groups=['all']) }}"
block:
- name: Test merge dicts via all group - Print the merged dict
ansible.builtin.debug:
msg: "{{ merged_dict }}"
- name: Test merge dicts via all group - Validate that the dict is complete
ansible.builtin.assert:
that:
- "(merged_dict.keys() | list | length) == 4"
- "'item1' in merged_dict"
- "'item2' in merged_dict"
- "'item3' in merged_dict"
- "'list_item' in merged_dict"
- "merged_dict.list_item | length == 3"
- name: Test merge dicts via two of three groups
delegate_to: localhost
vars:
merged_dict: "{{ lookup('community.general.merge_variables', '__merge_dict_in', pattern_type='suffix', groups=['dummy1', 'dummy2']) }}"
block:
- name: Test merge dicts via two of three groups - Print the merged dict
ansible.builtin.debug:
msg: "{{ merged_dict }}"
- name: Test merge dicts via two of three groups - Validate that the dict is complete
ansible.builtin.assert:
that:
- "(merged_dict.keys() | list | length) == 3"
- "'item1' in merged_dict"
- "'item2' in merged_dict"
- "'list_item' in merged_dict"
- "merged_dict.list_item | length == 2"
- name: Test merge dicts via two of three groups with inital value
delegate_to: localhost
vars:
initial_dict:
initial: initial_value
merged_dict: "{{ lookup('community.general.merge_variables', '__merge_dict_in', initial_value=initial_dict, pattern_type='suffix', groups=['dummy1', 'dummy2']) }}"
block:
- name: Test merge dicts via two of three groups with inital value - Print the merged dict
ansible.builtin.debug:
msg: "{{ merged_dict }}"
- name: Test merge dicts via two of three groups with inital value - Validate that the dict is complete
ansible.builtin.assert:
that:
- "(merged_dict.keys() | list | length) == 4"
- "'item1' in merged_dict"
- "'item2' in merged_dict"
- "'list_item' in merged_dict"
- "merged_dict.list_item | length == 2"