From dea872e4a66d3a45206733c2153e40112ada49b4 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 27 Sep 2017 19:53:10 -0400 Subject: [PATCH] avoid include_Xs conflating vars with options (#30954) * avoid include_Xs conflating vars with options * avoid frozenset so serialization wont complain * dded missing set * updated as per feedback --- lib/ansible/playbook/role_include.py | 12 ++++++------ lib/ansible/playbook/task_include.py | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py index 123579ef76..488790aee7 100644 --- a/lib/ansible/playbook/role_include.py +++ b/lib/ansible/playbook/role_include.py @@ -43,10 +43,10 @@ class IncludeRole(TaskInclude): circumstances related to the `- include_role: ...` """ - BASE = frozenset(['name', 'role']) # directly assigned - FROM_ARGS = frozenset(['tasks_from', 'vars_from', 'defaults_from']) # used to populate from dict in role - OTHER_ARGS = frozenset(['private', 'allow_duplicates']) # assigned to matching property - VALID_ARGS = frozenset(BASE.union(FROM_ARGS.union(OTHER_ARGS))) # all valid args + BASE = ('name', 'role') # directly assigned + FROM_ARGS = ('tasks_from', 'vars_from', 'defaults_from') # used to populate from dict in role + OTHER_ARGS = ('private', 'allow_duplicates') # assigned to matching property + VALID_ARGS = tuple(frozenset(BASE + FROM_ARGS + OTHER_ARGS)) # all valid args # ================================================================================= # ATTRIBUTES @@ -118,12 +118,12 @@ class IncludeRole(TaskInclude): raise AnsibleParserError('Invalid options for include_role: %s' % ','.join(list(bad_opts))) # build options for role includes - for key in IncludeRole.FROM_ARGS.intersection(my_arg_names): + for key in my_arg_names.intersection(IncludeRole.FROM_ARGS): from_key = key.replace('_from', '') ir._from_files[from_key] = basename(ir.args.get(key)) # manual list as otherwise the options would set other task parameters we don't want. - for option in IncludeRole.OTHER_ARGS.intersection(my_arg_names): + for option in my_arg_names.intersection(IncludeRole.OTHER_ARGS): setattr(ir, option, ir.args.get(option)) return ir diff --git a/lib/ansible/playbook/task_include.py b/lib/ansible/playbook/task_include.py index b190439560..f8612a02d3 100644 --- a/lib/ansible/playbook/task_include.py +++ b/lib/ansible/playbook/task_include.py @@ -61,18 +61,21 @@ class TaskInclude(Task): ''' We override the parent Task() classes get_vars here because we need to include the args of the include into the vars as - they are params to the included tasks. + they are params to the included tasks. But ONLY for 'include' ''' - all_vars = dict() - if self._parent: - all_vars.update(self._parent.get_vars()) + if self.action != 'include': + all_vars = super(TaskInclude, self).get_vars() + else: + all_vars = dict() + if self._parent: + all_vars.update(self._parent.get_vars()) - all_vars.update(self.vars) - all_vars.update(self.args) + all_vars.update(self.vars) + all_vars.update(self.args) - if 'tags' in all_vars: - del all_vars['tags'] - if 'when' in all_vars: - del all_vars['when'] + if 'tags' in all_vars: + del all_vars['tags'] + if 'when' in all_vars: + del all_vars['when'] return all_vars