1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Brian Coca 2017-09-27 19:53:10 -04:00 committed by GitHub
parent fc745920c7
commit dea872e4a6
2 changed files with 19 additions and 16 deletions

View file

@ -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

View file

@ -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