Fixes #4109 Filter plays by tags when using --list-hosts

pull/6725/head
James Tanner 11 years ago
parent 1faa840b67
commit c1f4142a29

@ -207,11 +207,9 @@ def main(args):
play = ansible.playbook.Play(pb, play_ds, play_basedir) play = ansible.playbook.Play(pb, play_ds, play_basedir)
label = play.name label = play.name
hosts = pb.inventory.list_hosts(play.hosts) hosts = pb.inventory.list_hosts(play.hosts)
if options.listhosts:
print ' play #%d (%s): host count=%d' % (playnum, label, len(hosts)) # Filter all tasks by given tags
for host in hosts: if pb.only_tags != 'all':
print ' %s' % host
if options.listtasks:
if options.subset and not hosts: if options.subset and not hosts:
continue continue
matched_tags, unmatched_tags = play.compare_tags(pb.only_tags) matched_tags, unmatched_tags = play.compare_tags(pb.only_tags)
@ -225,9 +223,17 @@ def main(args):
if unknown_tags: if unknown_tags:
continue continue
if options.listhosts:
print ' play #%d (%s): host count=%d' % (playnum, label, len(hosts))
for host in hosts:
print ' %s' % host
if options.listtasks:
print ' play #%d (%s):' % (playnum, label) print ' play #%d (%s):' % (playnum, label)
for task in play.tasks(): for task in play.tasks():
print "tags: %s" % task.tags
if (set(task.tags).intersection(pb.only_tags) and not if (set(task.tags).intersection(pb.only_tags) and not
set(task.tags).intersection(pb.skip_tags)): set(task.tags).intersection(pb.skip_tags)):
if getattr(task, 'name', None) is not None: if getattr(task, 'name', None) is not None:

Loading…
Cancel
Save