Don't pollute include_variables (#54687)

* Don't pollute include_variables. Fixes #51667. Fixes #54618.

* Rename include_variables to include_args, so we can make the distinction about what they are

* Track args and vars separately

* oops

* oops again

* linting fix

* Add test
This commit is contained in:
Matt Martz
2019-04-09 10:14:42 -05:00
committed by GitHub
parent dd20c7c04e
commit fbf2d5d2f4
7 changed files with 51 additions and 22 deletions

View File

@@ -0,0 +1,4 @@
- assert:
that:
- name == 'name_from_loop_var'
- name != 'loop_name_assert'

View File

@@ -94,3 +94,6 @@ test "$(egrep -c 'include handler task|ERROR! The requested handler '"'"'do_impo
# 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
# https://github.com/ansible/ansible/issues/54618
ansible-playbook test_loop_var_bleed.yaml "$@"

View File

@@ -0,0 +1,9 @@
- hosts: localhost
gather_facts: false
tasks:
- include_role:
name: loop_name_assert
loop:
- name_from_loop_var
loop_control:
loop_var: name

View File

@@ -51,11 +51,12 @@ def mock_variable_manager():
def test_included_file_instantiation():
filename = 'somefile.yml'
inc_file = IncludedFile(filename=filename, args=[], task=None)
inc_file = IncludedFile(filename=filename, args={}, vars={}, task=None)
assert isinstance(inc_file, IncludedFile)
assert inc_file._filename == filename
assert inc_file._args == []
assert inc_file._args == {}
assert inc_file._vars == {}
assert inc_file._task is None
@@ -84,6 +85,7 @@ def test_process_include_results(mock_iterator, mock_variable_manager):
assert res[0]._filename == os.path.join(os.getcwd(), 'include_test.yml')
assert res[0]._hosts == ['testhost1', 'testhost2']
assert res[0]._args == {}
assert res[0]._vars == {}
def test_process_include_diff_files(mock_iterator, mock_variable_manager):
@@ -124,6 +126,9 @@ def test_process_include_diff_files(mock_iterator, mock_variable_manager):
assert res[0]._args == {}
assert res[1]._args == {}
assert res[0]._vars == {}
assert res[1]._vars == {}
def test_process_include_simulate_free(mock_iterator, mock_variable_manager):
hostname = "testhost1"
@@ -159,3 +164,6 @@ def test_process_include_simulate_free(mock_iterator, mock_variable_manager):
assert res[0]._args == {}
assert res[1]._args == {}
assert res[0]._vars == {}
assert res[1]._vars == {}