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

Merge pull request #7393 from jimi-c/issue_7387_role_conditionals

Properly merge role conditionals in with pre-existing conditionals
This commit is contained in:
James Cammarata 2014-05-14 09:15:26 -05:00
commit 4e93b37abc

View file

@ -294,26 +294,24 @@ class Play(object):
else: else:
self.included_roles.append(dep) self.included_roles.append(dep)
def _merge_conditional(cur_conditionals, new_conditionals):
if isinstance(new_conditionals, (basestring, bool)):
cur_conditionals.append(new_conditionals)
elif isinstance(new_conditionals, list):
cur_conditionals.extend(new_conditionals)
# pass along conditionals from roles to dep roles # pass along conditionals from roles to dep roles
if type(role) is dict: passed_when = passed_vars.get('when')
if 'when' in passed_vars: role_when = role_vars.get('when')
if 'when' in dep_vars: dep_when = dep_vars.get('when')
tmpcond = [] tmpcond = []
_merge_conditional(tmpcond, passed_when)
if type(passed_vars['when']) is str: _merge_conditional(tmpcond, role_when)
tmpcond.append(passed_vars['when']) _merge_conditional(tmpcond, dep_when)
elif type(passed_vars['when']) is list:
tmpcond += passed_vars['when']
if type(dep_vars['when']) is str:
tmpcond.append(dep_vars['when'])
elif type(dep_vars['when']) is list:
tmpcond += dep_vars['when']
if len(tmpcond) > 0: if len(tmpcond) > 0:
dep_vars['when'] = tmpcond dep_vars['when'] = tmpcond
else:
dep_vars['when'] = passed_vars['when']
self._build_role_dependencies([dep], dep_stack, passed_vars=dep_vars, level=level+1) self._build_role_dependencies([dep], dep_stack, passed_vars=dep_vars, level=level+1)
dep_stack.append([dep,dep_path,dep_vars,dep_defaults_data]) dep_stack.append([dep,dep_path,dep_vars,dep_defaults_data])
@ -565,7 +563,10 @@ class Play(object):
task_vars = utils.combine_vars(task_vars, x['vars']) task_vars = utils.combine_vars(task_vars, x['vars'])
if 'when' in x: if 'when' in x:
if isinstance(x['when'], (basestring, bool)):
included_additional_conditions.append(x['when']) included_additional_conditions.append(x['when'])
elif isinstance(x['when'], list):
included_additional_conditions.extend(x['when'])
new_role = None new_role = None
if 'role_name' in x: if 'role_name' in x: