-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug(lookup/merge_variables): Fix rendering foreign variables (#8303)
* manually prepare variables of foreign host including hostvars property * render variables from context of current host * add integration test for cross host merge * lint fixes * adjust cross host merge unit tests to provide a tiny bit of the HostVars Class API * add license information * lint * add changelog fragment * Update tests/integration/targets/lookup_merge_variables/test_cross_host_merge_play.yml Okay Co-authored-by: Mark <[email protected]> * Update tests/integration/targets/lookup_merge_variables/test_cross_host_merge_play.yml Okay Co-authored-by: Mark <[email protected]> * Update tests/integration/targets/lookup_merge_variables/test_cross_host_merge_play.yml Okay Co-authored-by: Mark <[email protected]> * rename _HostVars to HostVarsMock * removing unnecessary task --------- Co-authored-by: Gitlab CI <[email protected]> Co-authored-by: Mark <[email protected]>
- Loading branch information
1 parent
bc7ad0f
commit 136419c
Showing
6 changed files
with
165 additions
and
83 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/8303-fix-rendering-foreign-variables.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- "merge_variables lookup plugin - fixing cross host merge: providing access to foreign hosts variables to the perspective of the host that is performing the merge (https://github.com/ansible-collections/community.general/pull/8303)." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/integration/targets/lookup_merge_variables/test_cross_host_merge_inventory.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
# 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 | ||
|
||
common: | ||
vars: | ||
provider_instances: | ||
servicedata1: | ||
host: "{{ hostvars[groups['provider'] | first].inventory_hostname }}" | ||
user: usr | ||
pass: pwd | ||
servicedata2: | ||
host: down | ||
user: usr2 | ||
pass: pwd2 | ||
hosts: | ||
host1: | ||
host2: | ||
|
||
consumer: | ||
vars: | ||
service_data: "{{ provider_instances.servicedata1 }}" | ||
merge2__1: "{{ service_data }}" # service_data is a variable only known to host2, so normally it´s not available for host1 that is performing the merge | ||
hosts: | ||
host2: | ||
|
||
provider: | ||
vars: | ||
merge_result: "{{ lookup('community.general.merge_variables', 'merge2__', pattern_type='prefix', groups=['consumer']) }}" | ||
hosts: | ||
host1: |
21 changes: 21 additions & 0 deletions
21
tests/integration/targets/lookup_merge_variables/test_cross_host_merge_play.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
# 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 (merging host reference variables) | ||
hosts: host1 | ||
connection: local | ||
gather_facts: false | ||
tasks: | ||
- name: Print merge result | ||
ansible.builtin.debug: | ||
msg: "{{ merge_result }}" | ||
- name: Validate merge result | ||
ansible.builtin.assert: | ||
that: | ||
- "merge_result | length == 3" | ||
- "merge_result.host == 'host1'" | ||
- "merge_result.user == 'usr'" | ||
- "merge_result.pass == 'pwd'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters