diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py index 123579ef764..488790aee74 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 b190439560e..f8612a02d30 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()) - - 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 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) + + if 'tags' in all_vars: + del all_vars['tags'] + if 'when' in all_vars: + del all_vars['when'] return all_vars