Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid include_Xs conflating vars with options #30954

Merged
merged 4 commits into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/ansible/playbook/role_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -118,12 +118,12 @@ def load(data, block=None, role=None, task_include=None, variable_manager=None,
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
Expand Down
27 changes: 15 additions & 12 deletions lib/ansible/playbook/task_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ def get_vars(self):
'''
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