IncludedFile: store _from args for proper deduplication (#85628)

* IncludedFile: store _from args for proper deduplication

Fixes #66497

Co-authored-by: Matt Martz <matt@sivel.net>
pull/85633/head
Martin Krizek 4 months ago committed by GitHub
parent 9ed7164ed6
commit 4c04b8c7c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- include_role - allow host specific values in all ``*_from`` arguments (https://github.com/ansible/ansible/issues/66497)

@ -203,7 +203,7 @@ class IncludedFile:
for from_arg in new_task.FROM_ARGS:
if from_arg in include_args:
from_key = from_arg.removesuffix('_from')
new_task._from_files[from_key] = include_args.pop(from_arg)
new_task._from_files[from_key] = include_args.get(from_arg)
inc_file = IncludedFile(role_name, include_args, special_vars, new_task, is_role=True)

@ -0,0 +1,18 @@
- hosts: testhost,localhost
tasks:
- include_role:
name: role_from_args
vars_from: "{{ inventory_hostname }}.yml"
tasks_from: "{{ inventory_hostname }}.yml"
- assert:
that:
- f1 is defined
- f1 == inventory_hostname
when: inventory_hostname == "testhost"
- assert:
that:
- f2 is defined
- f2 == inventory_hostname
when: inventory_hostname == "localhost"

@ -16,3 +16,5 @@ grep -q "'include_tasks' is not a valid attribute for a Play" <<< "$result"
ansible-playbook includes_loop_rescue.yml --extra-vars strategy=linear "$@"
ansible-playbook includes_loop_rescue.yml --extra-vars strategy=free "$@"
ansible-playbook includes_from_dedup.yml -i ../../inventory "$@"

@ -312,8 +312,8 @@ def test_process_include_simulate_free_block_role_tasks(mock_iterator, mock_vari
assert res[0]._hosts == [host1]
assert res[1]._hosts == [host2]
assert res[0]._args == {}
assert res[1]._args == {}
assert res[0]._args == {'tasks_from': 'task1.yml'}
assert res[1]._args == {'tasks_from': 'task2.yml'}
assert res[0]._vars == {}
assert res[1]._vars == {}

Loading…
Cancel
Save