diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index 2e3f8225334..e0e09373ca6 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -144,6 +144,8 @@ class IncludedFile: include_file = loader.path_dwim(include_result['include']) include_file = templar.template(include_file) + # Update the task args to reflect the expanded/templated path + original_task.args['_raw_params'] = include_file inc_file = IncludedFile(include_file, include_variables, original_task) else: # template the included role's name here diff --git a/test/integration/targets/include_import/include_path_inheritance/one/include_me.yml b/test/integration/targets/include_import/include_path_inheritance/one/include_me.yml new file mode 100644 index 00000000000..ea345d28527 --- /dev/null +++ b/test/integration/targets/include_import/include_path_inheritance/one/include_me.yml @@ -0,0 +1,2 @@ +- debug: + msg: one diff --git a/test/integration/targets/include_import/include_path_inheritance/playbook.yml b/test/integration/targets/include_import/include_path_inheritance/playbook.yml new file mode 100644 index 00000000000..b92e0f5d588 --- /dev/null +++ b/test/integration/targets/include_import/include_path_inheritance/playbook.yml @@ -0,0 +1,14 @@ +- hosts: testhost:testhost2 + tasks: + - set_fact: + include_me: one + when: inventory_hostname == ansible_play_hosts[0] + + - set_fact: + include_me: two + when: inventory_hostname == ansible_play_hosts[1] + + - debug: + var: include_me + + - include_tasks: '{{ include_me }}/include_me.yml' diff --git a/test/integration/targets/include_import/include_path_inheritance/two/include_me.yml b/test/integration/targets/include_import/include_path_inheritance/two/include_me.yml new file mode 100644 index 00000000000..96855323a0e --- /dev/null +++ b/test/integration/targets/include_import/include_path_inheritance/two/include_me.yml @@ -0,0 +1,2 @@ +- debug: + msg: two diff --git a/test/integration/targets/include_import/runme.sh b/test/integration/targets/include_import/runme.sh index ef20bebc6d6..4d1990812b1 100755 --- a/test/integration/targets/include_import/runme.sh +++ b/test/integration/targets/include_import/runme.sh @@ -63,3 +63,7 @@ ANSIBLE_STRATEGY='linear' ansible-playbook test_grandparent_inheritance.yml -i . # undefined_var ANSIBLE_STRATEGY='linear' ansible-playbook undefined_var/playbook.yml -i ../../inventory "$@" ANSIBLE_STRATEGY='free' ansible-playbook undefined_var/playbook.yml -i ../../inventory "$@" + +# Include path inheritance using host var for include file path +ANSIBLE_STRATEGY='linear' ansible-playbook include_path_inheritance/playbook.yml -i ../../inventory "$@" +ANSIBLE_STRATEGY='free' ansible-playbook include_path_inheritance/playbook.yml -i ../../inventory "$@"