Give IncludedFile more context via ansible_search_path (#50045)

* Give IncludedFile more context via ansible_search_path to template lookups. Fixes #49969

* Update units
This commit is contained in:
Matt Martz
2019-01-03 15:13:02 -06:00
committed by ansibot
parent 6620facd19
commit 3b49bbcfde
8 changed files with 50 additions and 2 deletions

View File

@@ -0,0 +1,11 @@
# https://github.com/ansible/ansible/issues/49969
- hosts: localhost
gather_facts: false
tasks:
- include_role:
name: test
public: true
- assert:
that:
- included_other is defined

View File

@@ -0,0 +1 @@
- include_tasks: other.yml

View File

@@ -0,0 +1 @@
- include_tasks: "{{ lookup('first_found', inventory_hostname ~ '.yml') }}"

View File

@@ -0,0 +1,2 @@
- set_fact:
included_other: true

View File

@@ -90,3 +90,7 @@ ansible-playbook run_once/playbook.yml "$@"
# https://github.com/ansible/ansible/issues/48936
ansible-playbook -v handler_addressing/playbook.yml 2>&1 | tee test_handler_addressing.out
test "$(egrep -c 'include handler task|ERROR! The requested handler '"'"'do_import'"'"' was not found' test_handler_addressing.out)" = 2
# https://github.com/ansible/ansible/issues/49969
ansible-playbook -v parent_templating/playbook.yml 2>&1 | tee test_parent_templating.out
test "$(egrep -c 'Templating the path of the parent include_tasks failed.' test_parent_templating.out)" = 0

View File

@@ -65,6 +65,7 @@ def test_process_include_results(mock_iterator, mock_variable_manager):
parent_task_ds = {'debug': 'msg=foo'}
parent_task = Task.load(parent_task_ds)
parent_task._play = None
task_ds = {'include': 'include_test.yml'}
loaded_task = TaskInclude.load(task_ds, task_include=parent_task)
@@ -91,12 +92,15 @@ def test_process_include_diff_files(mock_iterator, mock_variable_manager):
parent_task_ds = {'debug': 'msg=foo'}
parent_task = Task.load(parent_task_ds)
parent_task._play = None
task_ds = {'include': 'include_test.yml'}
loaded_task = TaskInclude.load(task_ds, task_include=parent_task)
loaded_task._play = None
child_task_ds = {'include': 'other_include_test.yml'}
loaded_child_task = TaskInclude.load(child_task_ds, task_include=loaded_task)
loaded_child_task._play = None
return_data = {'include': 'include_test.yml'}
# The task in the TaskResult has to be a TaskInclude so it has a .static attr
@@ -129,6 +133,9 @@ def test_process_include_simulate_free(mock_iterator, mock_variable_manager):
parent_task1 = Task.load(parent_task_ds)
parent_task2 = Task.load(parent_task_ds)
parent_task1._play = None
parent_task2._play = None
task_ds = {'include': 'include_test.yml'}
loaded_task1 = TaskInclude.load(task_ds, task_include=parent_task1)
loaded_task2 = TaskInclude.load(task_ds, task_include=parent_task2)