Skip to content

Commit

Permalink
Update TaskInclude _raw_params with the expanded/templated path to f…
Browse files Browse the repository at this point in the history
…ile (ansible#39365)

* Update TaskInclude _raw_params with the expanded/templated path to file

* Add tests to validate host vars include paths
  • Loading branch information
sivel authored Apr 26, 2018
1 parent 2f51616 commit 4b01b92
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ansible/playbook/included_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def process_include_results(results, iterator, loader, variable_manager):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- debug:
msg: one
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- debug:
msg: two
4 changes: 4 additions & 0 deletions test/integration/targets/include_import/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"

0 comments on commit 4b01b92

Please sign in to comment.