added list-tags option and also show tags in list-tasks option

pull/10414/head
Brian Coca 10 years ago
parent 919db1025c
commit 8267bb2ae1

@ -91,6 +91,8 @@ def main(args):
help="perform a syntax check on the playbook, but do not execute it") help="perform a syntax check on the playbook, but do not execute it")
parser.add_option('--list-tasks', dest='listtasks', action='store_true', parser.add_option('--list-tasks', dest='listtasks', action='store_true',
help="list all tasks that would be executed") help="list all tasks that would be executed")
parser.add_option('--list-tags', dest='listtags', action='store_true',
help="list all available tags")
parser.add_option('--step', dest='step', action='store_true', parser.add_option('--step', dest='step', action='store_true',
help="one-step-at-a-time: confirm each task before running") help="one-step-at-a-time: confirm each task before running")
parser.add_option('--start-at-task', dest='start_at', parser.add_option('--start-at-task', dest='start_at',
@ -123,7 +125,7 @@ def main(args):
options.ask_vault_pass = options.ask_vault_pass or C.DEFAULT_ASK_VAULT_PASS options.ask_vault_pass = options.ask_vault_pass or C.DEFAULT_ASK_VAULT_PASS
if options.listhosts or options.syntax or options.listtasks: if options.listhosts or options.syntax or options.listtasks or options.listtags:
(_, _, _, vault_pass) = utils.ask_passwords(ask_vault_pass=options.ask_vault_pass) (_, _, _, vault_pass) = utils.ask_passwords(ask_vault_pass=options.ask_vault_pass)
else: else:
options.ask_pass = options.ask_pass or C.DEFAULT_ASK_PASS options.ask_pass = options.ask_pass or C.DEFAULT_ASK_PASS
@ -215,7 +217,7 @@ def main(args):
display(callbacks.banner("FLUSHING FACT CACHE")) display(callbacks.banner("FLUSHING FACT CACHE"))
pb.SETUP_CACHE.flush() pb.SETUP_CACHE.flush()
if options.listhosts or options.listtasks or options.syntax: if options.listhosts or options.listtasks or options.syntax or options.listtags:
print '' print ''
print 'playbook: %s' % playbook print 'playbook: %s' % playbook
print '' print ''
@ -232,14 +234,23 @@ def main(args):
for host in hosts: for host in hosts:
print ' %s' % host print ' %s' % host
if options.listtasks: if options.listtags or options.listtasks:
print ' play #%d (%s):' % (playnum, label) print ' play #%d (%s):\tTAGS: [%s]' % (playnum, label,','.join(sorted(set(play.tags))))
for task in pb.tasks_to_run_in_play(play): if options.listtags:
if getattr(task, 'name', None) is not None: tags = []
# meta tasks have no names for task in pb.tasks_to_run_in_play(play):
print ' %s' % task.name tags.extend(task.tags)
if options.listhosts or options.listtasks: print ' TASK TAGS: [%s]' % (', '.join(sorted(set(tags).difference(['untagged']))))
if options.listtasks:
for task in pb.tasks_to_run_in_play(play):
if getattr(task, 'name', None) is not None:
# meta tasks have no names
print ' %s\tTAGS: [%s]' % (task.name, ', '.join(sorted(set(task.tags).difference(['untagged']))))
if options.listhosts or options.listtasks or options.listtags:
print '' print ''
continue continue

Loading…
Cancel
Save