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
pull/30935/merge
Brian Coca 7 years ago committed by GitHub
parent fc745920c7
commit dea872e4a6

@ -43,10 +43,10 @@ class IncludeRole(TaskInclude):
circumstances related to the `- include_role: ...` circumstances related to the `- include_role: ...`
""" """
BASE = frozenset(['name', 'role']) # directly assigned BASE = ('name', 'role') # directly assigned
FROM_ARGS = frozenset(['tasks_from', 'vars_from', 'defaults_from']) # used to populate from dict in role FROM_ARGS = ('tasks_from', 'vars_from', 'defaults_from') # used to populate from dict in role
OTHER_ARGS = frozenset(['private', 'allow_duplicates']) # assigned to matching property OTHER_ARGS = ('private', 'allow_duplicates') # assigned to matching property
VALID_ARGS = frozenset(BASE.union(FROM_ARGS.union(OTHER_ARGS))) # all valid args VALID_ARGS = tuple(frozenset(BASE + FROM_ARGS + OTHER_ARGS)) # all valid args
# ================================================================================= # =================================================================================
# ATTRIBUTES # ATTRIBUTES
@ -118,12 +118,12 @@ class IncludeRole(TaskInclude):
raise AnsibleParserError('Invalid options for include_role: %s' % ','.join(list(bad_opts))) raise AnsibleParserError('Invalid options for include_role: %s' % ','.join(list(bad_opts)))
# build options for role includes # 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', '') from_key = key.replace('_from', '')
ir._from_files[from_key] = basename(ir.args.get(key)) 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. # 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)) setattr(ir, option, ir.args.get(option))
return ir return ir

@ -61,18 +61,21 @@ class TaskInclude(Task):
''' '''
We override the parent Task() classes get_vars here because We override the parent Task() classes get_vars here because
we need to include the args of the include into the vars as 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.action != 'include':
if self._parent: all_vars = super(TaskInclude, self).get_vars()
all_vars.update(self._parent.get_vars()) else:
all_vars = dict()
all_vars.update(self.vars) if self._parent:
all_vars.update(self.args) all_vars.update(self._parent.get_vars())
if 'tags' in all_vars: all_vars.update(self.vars)
del all_vars['tags'] all_vars.update(self.args)
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 return all_vars

Loading…
Cancel
Save