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

pull/4185/merge
James Cammarata 11 years ago
parent 7272aa0347
commit 27e8675277

@ -347,7 +347,12 @@ class PlayBook(object):
ansible.callbacks.set_task(self.callbacks, task) ansible.callbacks.set_task(self.callbacks, task)
ansible.callbacks.set_task(self.runner_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: if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task:
ansible.callbacks.set_task(self.callbacks, None) ansible.callbacks.set_task(self.callbacks, None)
ansible.callbacks.set_task(self.runner_callbacks, None) ansible.callbacks.set_task(self.runner_callbacks, None)

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

@ -25,7 +25,7 @@ class Task(object):
__slots__ = [ __slots__ = [
'name', 'meta', 'action', 'only_if', 'when', 'async_seconds', 'async_poll_interval', 'name', 'meta', 'action', 'only_if', 'when', 'async_seconds', 'async_poll_interval',
'notify', 'module_name', 'module_args', 'module_vars', 'default_vars', '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', 'delegate_to', 'first_available_file', 'ignore_errors',
'local_action', 'transport', 'sudo', 'sudo_user', 'sudo_pass', 'local_action', 'transport', 'sudo', 'sudo_user', 'sudo_pass',
'items_lookup_plugin', 'items_lookup_terms', 'environment', 'args', 'items_lookup_plugin', 'items_lookup_terms', 'environment', 'args',
@ -110,6 +110,7 @@ class Task(object):
self.register = ds.get('register', None) self.register = ds.get('register', None)
self.sudo = utils.boolean(ds.get('sudo', play.sudo)) self.sudo = utils.boolean(ds.get('sudo', play.sudo))
self.environment = ds.get('environment', {}) 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 # 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 # can be hashes and lists, not just scalars
@ -159,10 +160,6 @@ 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…
Cancel
Save