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

Make the role_name in the task its own field for use in the callback

This commit is contained in:
James Cammarata 2013-09-20 15:46:34 -05:00
parent 7272aa0347
commit 27e8675277
3 changed files with 15 additions and 11 deletions

View file

@ -347,7 +347,12 @@ class PlayBook(object):
ansible.callbacks.set_task(self.callbacks, task)
ansible.callbacks.set_task(self.runner_callbacks, task)
self.callbacks.on_task_start(template(play.basedir, task.name, task.module_vars, lookup_fatal=False, filter_fatal=False), is_handler)
if task.role_name:
name = '%s|%s' % (task.role_name, task.name)
else:
name = task.name
self.callbacks.on_task_start(template(play.basedir, name, task.module_vars, lookup_fatal=False, filter_fatal=False), is_handler)
if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task:
ansible.callbacks.set_task(self.callbacks, None)
ansible.callbacks.set_task(self.runner_callbacks, None)

View file

@ -285,18 +285,20 @@ 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):
if isinstance(role, dict):
role_name = role['role']
else:
role_name = role
if os.path.isfile(task):
nt = dict(include=pipes.quote(task), vars=role_vars, default_vars=default_vars, role_name=role_name)
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_name)
for k in special_keys:
if k in special_vars:
nt[k] = special_vars[k]

View file

@ -25,7 +25,7 @@ class Task(object):
__slots__ = [
'name', 'meta', 'action', 'only_if', 'when', 'async_seconds', 'async_poll_interval',
'notify', 'module_name', 'module_args', 'module_vars', 'default_vars',
'play', 'notified_by', 'tags', 'register',
'play', 'notified_by', 'tags', 'register', 'role_name',
'delegate_to', 'first_available_file', 'ignore_errors',
'local_action', 'transport', 'sudo', 'sudo_user', 'sudo_pass',
'items_lookup_plugin', 'items_lookup_terms', 'environment', 'args',
@ -110,6 +110,7 @@ class Task(object):
self.register = ds.get('register', None)
self.sudo = utils.boolean(ds.get('sudo', play.sudo))
self.environment = ds.get('environment', {})
self.role_name = role_name
# rather than simple key=value args on the options line, these represent structured data and the values
# can be hashes and lists, not just scalars
@ -159,10 +160,6 @@ 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)