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

being run against for each playbook
pull/881/head
Seth Vidal 12 years ago
parent ffabded2e6
commit 8e039a6389

@ -57,6 +57,8 @@ def main(args):
help="set additional key=value variables from the CLI") help="set additional key=value variables from the CLI")
parser.add_option('-t', '--tags', dest='tags', default='all', parser.add_option('-t', '--tags', dest='tags', default='all',
help="only run plays and tasks tagged with these values") 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) options, args = parser.parse_args(args)
@ -66,6 +68,7 @@ def main(args):
sshpass = None sshpass = None
sudopass = None sudopass = None
if not options.listhosts:
if options.ask_pass: if options.ask_pass:
sshpass = getpass.getpass(prompt="SSH password: ") sshpass = getpass.getpass(prompt="SSH password: ")
if options.ask_sudo_pass: if options.ask_sudo_pass:
@ -104,6 +107,21 @@ def main(args):
only_tags=only_tags, only_tags=only_tags,
subset=options.subset, 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: try:
pb.run() pb.run()

Loading…
Cancel
Save