mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
c2e02fbd6b
commit
a5ee6ff1e5
2 changed files with 15 additions and 7 deletions
|
@ -286,13 +286,13 @@ class Play(object):
|
||||||
if not os.path.isfile(task) and not os.path.isfile(handler) and not os.path.isfile(vars_file) and not os.path.isdir(library):
|
if not os.path.isfile(task) and not os.path.isfile(handler) and not os.path.isfile(vars_file) and not os.path.isdir(library):
|
||||||
raise errors.AnsibleError("found role at %s, but cannot find %s or %s or %s or %s" % (role_path, task, handler, vars_file, library))
|
raise errors.AnsibleError("found role at %s, but cannot find %s or %s or %s or %s" % (role_path, task, handler, vars_file, library))
|
||||||
if os.path.isfile(task):
|
if os.path.isfile(task):
|
||||||
nt = dict(include=pipes.quote(task), vars=role_vars, default_vars=default_vars)
|
nt = dict(include=pipes.quote(task), vars=role_vars, default_vars=default_vars, role_name=role['role'])
|
||||||
for k in special_keys:
|
for k in special_keys:
|
||||||
if k in special_vars:
|
if k in special_vars:
|
||||||
nt[k] = special_vars[k]
|
nt[k] = special_vars[k]
|
||||||
new_tasks.append(nt)
|
new_tasks.append(nt)
|
||||||
if os.path.isfile(handler):
|
if os.path.isfile(handler):
|
||||||
nt = dict(include=pipes.quote(handler), vars=role_vars)
|
nt = dict(include=pipes.quote(handler), vars=role_vars, role_name=role['role'])
|
||||||
for k in special_keys:
|
for k in special_keys:
|
||||||
if k in special_vars:
|
if k in special_vars:
|
||||||
nt[k] = special_vars[k]
|
nt[k] = special_vars[k]
|
||||||
|
@ -356,7 +356,7 @@ class Play(object):
|
||||||
|
|
||||||
# *************************************************
|
# *************************************************
|
||||||
|
|
||||||
def _load_tasks(self, tasks, vars={}, default_vars={}, sudo_vars={}, additional_conditions=[], original_file=None):
|
def _load_tasks(self, tasks, vars={}, default_vars={}, sudo_vars={}, additional_conditions=[], original_file=None, role_name=None):
|
||||||
''' handle task and handler include statements '''
|
''' handle task and handler include statements '''
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
@ -403,7 +403,7 @@ class Play(object):
|
||||||
included_additional_conditions.insert(0, utils.compile_when_to_only_if("%s %s" % (k[5:], x[k])))
|
included_additional_conditions.insert(0, utils.compile_when_to_only_if("%s %s" % (k[5:], x[k])))
|
||||||
elif k == 'when':
|
elif k == 'when':
|
||||||
included_additional_conditions.insert(0, utils.compile_when_to_only_if("jinja2_compare %s" % x[k]))
|
included_additional_conditions.insert(0, utils.compile_when_to_only_if("jinja2_compare %s" % x[k]))
|
||||||
elif k in ("include", "vars", "default_vars", "only_if", "sudo", "sudo_user"):
|
elif k in ("include", "vars", "default_vars", "only_if", "sudo", "sudo_user", "role_name"):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
include_vars[k] = x[k]
|
include_vars[k] = x[k]
|
||||||
|
@ -424,6 +424,10 @@ class Play(object):
|
||||||
if 'only_if' in x:
|
if 'only_if' in x:
|
||||||
included_additional_conditions.append(x['only_if'])
|
included_additional_conditions.append(x['only_if'])
|
||||||
|
|
||||||
|
new_role = None
|
||||||
|
if 'role_name' in x:
|
||||||
|
new_role = x['role_name']
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
mv = task_vars.copy()
|
mv = task_vars.copy()
|
||||||
mv['item'] = item
|
mv['item'] = item
|
||||||
|
@ -436,9 +440,9 @@ class Play(object):
|
||||||
include_file = template(dirname, tokens[0], mv)
|
include_file = template(dirname, tokens[0], mv)
|
||||||
include_filename = utils.path_dwim(dirname, include_file)
|
include_filename = utils.path_dwim(dirname, include_file)
|
||||||
data = utils.parse_yaml_from_file(include_filename)
|
data = utils.parse_yaml_from_file(include_filename)
|
||||||
results += self._load_tasks(data, mv, default_vars, included_sudo_vars, included_additional_conditions, original_file=include_filename)
|
results += self._load_tasks(data, mv, default_vars, included_sudo_vars, included_additional_conditions, original_file=include_filename, role_name=new_role)
|
||||||
elif type(x) == dict:
|
elif type(x) == dict:
|
||||||
results.append(Task(self,x,module_vars=task_vars,default_vars=default_vars,additional_conditions=additional_conditions))
|
results.append(Task(self,x,module_vars=task_vars,default_vars=default_vars,additional_conditions=additional_conditions,role_name=role_name))
|
||||||
else:
|
else:
|
||||||
raise Exception("unexpected task type")
|
raise Exception("unexpected task type")
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Task(object):
|
||||||
'any_errors_fatal', 'changed_when', 'failed_when', 'always_run'
|
'any_errors_fatal', 'changed_when', 'failed_when', 'always_run'
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, play, ds, module_vars=None, default_vars=None, additional_conditions=None):
|
def __init__(self, play, ds, module_vars=None, default_vars=None, additional_conditions=None, role_name=None):
|
||||||
''' constructor loads from a task or handler datastructure '''
|
''' constructor loads from a task or handler datastructure '''
|
||||||
|
|
||||||
# meta directives are used to tell things like ansible/playbook to run
|
# meta directives are used to tell things like ansible/playbook to run
|
||||||
|
@ -159,6 +159,10 @@ class Task(object):
|
||||||
if self.name is None:
|
if self.name is None:
|
||||||
self.name = self.action
|
self.name = self.action
|
||||||
|
|
||||||
|
# prepend the role name this task is from, if there was one
|
||||||
|
if role_name:
|
||||||
|
self.name = "%s|%s" % (role_name, self.name)
|
||||||
|
|
||||||
# load various attributes
|
# load various attributes
|
||||||
self.only_if = ds.get('only_if', 'True')
|
self.only_if = ds.get('only_if', 'True')
|
||||||
self.when = ds.get('when', None)
|
self.when = ds.get('when', None)
|
||||||
|
|
Loading…
Reference in a new issue