diff options
author | Matt Martz <matt@sivel.net> | 2019-04-09 10:14:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-09 10:14:42 -0500 |
commit | fbf2d5d2f44d76a607edd17132c0386fb22702e2 (patch) | |
tree | 0218a537ab5b9f6842337b8bcaa6445d6c2c5cb6 /lib/ansible/playbook | |
parent | dd20c7c04e027f5989d3f779ee9cc48eb54bcbf8 (diff) | |
download | ansible-fbf2d5d2f44d76a607edd17132c0386fb22702e2.tar.gz |
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
Diffstat (limited to 'lib/ansible/playbook')
-rw-r--r-- | lib/ansible/playbook/included_file.py | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index 6f0b0bfc72..5500b7f00b 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -33,9 +33,10 @@ display = Display() class IncludedFile: - def __init__(self, filename, args, task, is_role=False): + def __init__(self, filename, args, vars, task, is_role=False): self._filename = filename self._args = args + self._vars = vars self._task = task self._hosts = [] self._is_role = is_role @@ -47,10 +48,13 @@ class IncludedFile: raise ValueError() def __eq__(self, other): - return other._filename == self._filename and other._args == self._args and other._task._parent._uuid == self._task._parent._uuid + return (other._filename == self._filename and + other._args == self._args and + other._vars == self._vars and + other._task._parent._uuid == self._task._parent._uuid) def __repr__(self): - return "%s (%s): %s" % (self._filename, self._args, self._hosts) + return "%s (args=%s vars=%s): %s" % (self._filename, self._args, self._vars, self._hosts) @staticmethod def process_include_results(results, iterator, loader, variable_manager): @@ -81,20 +85,21 @@ class IncludedFile: except KeyError: task_vars = task_vars_cache[cache_key] = variable_manager.get_vars(play=iterator._play, host=original_host, task=original_task) - include_variables = include_result.get('include_variables', dict()) + include_args = include_result.get('include_args', dict()) + special_vars = {} loop_var = 'item' index_var = None if original_task.loop_control: loop_var = original_task.loop_control.loop_var index_var = original_task.loop_control.index_var if loop_var in include_result: - task_vars[loop_var] = include_variables[loop_var] = include_result[loop_var] + task_vars[loop_var] = special_vars[loop_var] = include_result[loop_var] if index_var and index_var in include_result: - task_vars[index_var] = include_variables[index_var] = include_result[index_var] + task_vars[index_var] = special_vars[index_var] = include_result[index_var] if '_ansible_item_label' in include_result: - task_vars['_ansible_item_label'] = include_variables['_ansible_item_label'] = include_result['_ansible_item_label'] - if original_task.no_log and '_ansible_no_log' not in include_variables: - task_vars['_ansible_no_log'] = include_variables['_ansible_no_log'] = original_task.no_log + task_vars['_ansible_item_label'] = special_vars['_ansible_item_label'] = include_result['_ansible_item_label'] + if original_task.no_log and '_ansible_no_log' not in include_args: + task_vars['_ansible_no_log'] = special_vars['_ansible_no_log'] = original_task.no_log # get search path for this task to pass to lookup plugins that may be used in pathing to # the included file @@ -166,21 +171,21 @@ class IncludedFile: include_file = loader.path_dwim(include_result['include']) include_file = templar.template(include_file) - inc_file = IncludedFile(include_file, include_variables, original_task) + inc_file = IncludedFile(include_file, include_args, special_vars, original_task) else: # template the included role's name here - role_name = include_variables.pop('name', include_variables.pop('role', None)) + role_name = include_args.pop('name', include_args.pop('role', None)) if role_name is not None: role_name = templar.template(role_name) new_task = original_task.copy() new_task._role_name = role_name for from_arg in new_task.FROM_ARGS: - if from_arg in include_variables: + if from_arg in include_args: from_key = from_arg.replace('_from', '') - new_task._from_files[from_key] = templar.template(include_variables.pop(from_arg)) + new_task._from_files[from_key] = templar.template(include_args.pop(from_arg)) - inc_file = IncludedFile(role_name, include_variables, new_task, is_role=True) + inc_file = IncludedFile(role_name, include_args, special_vars, new_task, is_role=True) idx = 0 orig_inc_file = inc_file |