add --list-hosts option to ansible-playbook to dump out the hosts

being run against for each playbook
This commit is contained in:
Seth Vidal 2012-08-15 14:19:45 -04:00
parent ffabded2e6
commit 8e039a6389

View file

@ -57,6 +57,8 @@ def main(args):
help="set additional key=value variables from the CLI")
parser.add_option('-t', '--tags', dest='tags', default='all',
help="only run plays and tasks tagged with these values")
parser.add_option('--list-hosts', dest='listhosts', action='store_true',
help="dump out a list of hosts, each play will run against, does not run playbook!")
options, args = parser.parse_args(args)
@ -66,6 +68,7 @@ def main(args):
sshpass = None
sudopass = None
if not options.listhosts:
if options.ask_pass:
sshpass = getpass.getpass(prompt="SSH password: ")
if options.ask_sudo_pass:
@ -104,6 +107,21 @@ def main(args):
only_tags=only_tags,
subset=options.subset,
)
if options.listhosts:
playnum = 0
for play in pb.playbook:
playnum += 1
if 'hosts' in play:
label = 'unnamed'
if 'name' in play:
label = play['name']
print 'hosts in play %s: %s' % (playnum, label)
for host in pb.inventory.list_hosts(play['hosts']):
print ' %s' % host
print '\n'
return 0
try:
pb.run()