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>
This commit is contained in:
Martin Krizek
2025-08-07 15:52:47 -04:00
committed by GitHub
co-authored by Matt Martz
parent 9ed7164ed6
commit 4c04b8c7c3
9 changed files with 31 additions and 3 deletions
@@ -0,0 +1,2 @@
bugfixes:
- include_role - allow host specific values in all ``*_from`` arguments (https://github.com/ansible/ansible/issues/66497)
+1 -1
View File
@@ -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"
@@ -0,0 +1,2 @@
- set_fact:
f2: "{{ v }}"
@@ -0,0 +1,2 @@
- set_fact:
f1: "{{ v }}"
@@ -0,0 +1 @@
v: localhost
@@ -0,0 +1 @@
v: testhost
@@ -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 "$@"
+2 -2
View File
@@ -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 == {}