Make --list-tasks respect tags
Also makes the output closer to the appearance of v1 Fixes #13260
This commit is contained in:
parent
8c6f56f982
commit
5929ffc7c3
1 changed files with 12 additions and 18 deletions
|
@ -30,6 +30,7 @@ from ansible.errors import AnsibleError, AnsibleOptionsError
|
|||
from ansible.executor.playbook_executor import PlaybookExecutor
|
||||
from ansible.inventory import Inventory
|
||||
from ansible.parsing.dataloader import DataLoader
|
||||
from ansible.playbook.play_context import PlayContext
|
||||
from ansible.utils.vars import load_extra_vars
|
||||
from ansible.vars import VariableManager
|
||||
|
||||
|
@ -152,18 +153,10 @@ class PlaybookCLI(CLI):
|
|||
for p in results:
|
||||
|
||||
display.display('\nplaybook: %s' % p['playbook'])
|
||||
i = 1
|
||||
for play in p['plays']:
|
||||
if play.name:
|
||||
playname = play.name
|
||||
else:
|
||||
playname = '#' + str(i)
|
||||
|
||||
msg = "\n PLAY: %s" % (playname)
|
||||
mytags = set()
|
||||
if self.options.listtags and play.tags:
|
||||
mytags = mytags.union(set(play.tags))
|
||||
msg += ' TAGS: [%s]' % (','.join(mytags))
|
||||
for idx, play in enumerate(p['plays']):
|
||||
msg = "\n play #%d (%s): %s" % (idx + 1, ','.join(play.hosts), play.name)
|
||||
mytags = set(play.tags)
|
||||
msg += ' TAGS: [%s]' % (','.join(mytags))
|
||||
|
||||
if self.options.listhosts:
|
||||
playhosts = set(inventory.get_hosts(play.hosts))
|
||||
|
@ -176,20 +169,21 @@ class PlaybookCLI(CLI):
|
|||
if self.options.listtags or self.options.listtasks:
|
||||
taskmsg = ' tasks:'
|
||||
|
||||
all_vars = variable_manager.get_vars(loader=loader, play=play)
|
||||
play_context = PlayContext(play=play, options=self.options)
|
||||
for block in play.compile():
|
||||
block = block.filter_tagged_tasks(play_context, all_vars)
|
||||
if not block.has_tasks():
|
||||
continue
|
||||
|
||||
j = 1
|
||||
for task in block.block:
|
||||
taskmsg += "\n %s" % task
|
||||
if self.options.listtags and task.tags:
|
||||
taskmsg += " TAGS: [%s]" % ','.join(mytags.union(set(task.tags)))
|
||||
j = j + 1
|
||||
if task.action == 'meta':
|
||||
continue
|
||||
taskmsg += "\n %s" % task.get_name()
|
||||
taskmsg += " TAGS: [%s]" % ','.join(mytags.union(set(task.tags)))
|
||||
|
||||
display.display(taskmsg)
|
||||
|
||||
i = i + 1
|
||||
return 0
|
||||
else:
|
||||
return results
|
||||
|
|
Loading…
Reference in a new issue