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

Display parent role name of tasks in the name line

Fixes #4076
This commit is contained in:
James Cammarata 2013-09-19 20:44:52 -05:00
parent c2e02fbd6b
commit a5ee6ff1e5
2 changed files with 15 additions and 7 deletions

View file

@ -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):
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):
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:
if k in special_vars:
nt[k] = special_vars[k]
new_tasks.append(nt)
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:
if k in special_vars:
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 '''
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])))
elif k == 'when':
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
else:
include_vars[k] = x[k]
@ -424,6 +424,10 @@ class Play(object):
if 'only_if' in x:
included_additional_conditions.append(x['only_if'])
new_role = None
if 'role_name' in x:
new_role = x['role_name']
for item in items:
mv = task_vars.copy()
mv['item'] = item
@ -436,9 +440,9 @@ class Play(object):
include_file = template(dirname, tokens[0], mv)
include_filename = utils.path_dwim(dirname, include_file)
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:
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:
raise Exception("unexpected task type")

View file

@ -41,7 +41,7 @@ class Task(object):
'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 '''
# meta directives are used to tell things like ansible/playbook to run
@ -159,6 +159,10 @@ class Task(object):
if self.name is None:
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
self.only_if = ds.get('only_if', 'True')
self.when = ds.get('when', None)