Don't prompt for password info if the pattern wouldn't have matched any hosts. Also convert

Runner() usage to the new inventory model.
This commit is contained in:
Michael DeHaan 2012-04-21 11:46:32 -04:00
parent 3081bb93f1
commit a8d748220b

View file

@ -29,6 +29,7 @@ import ansible.constants as C
from ansible import utils
from ansible import errors
from ansible import callbacks
from ansible import inventory
########################################################
@ -69,6 +70,13 @@ class Cli(object):
''' use Runner lib to do SSH things '''
pattern = args[0]
inventory_manager = inventory.Inventory(options.inventory)
hosts = inventory_manager.list_hosts(pattern)
if len(hosts) == 0:
print >>sys.stderr, "No hosts matched"
sys.exit(1)
sshpass = None
sudopass = None
if options.ask_pass:
@ -78,7 +86,6 @@ class Cli(object):
if options.tree:
utils.prepare_writeable_dir(options.tree)
if options.seconds:
print "background launch...\n\n"
@ -86,7 +93,7 @@ class Cli(object):
module_name=options.module_name, module_path=options.module_path,
module_args=options.module_args,
remote_user=options.remote_user, remote_pass=sshpass,
host_list=options.inventory, timeout=options.timeout,
inventory=inventory_manager, timeout=options.timeout,
forks=options.forks,
background=options.seconds, pattern=pattern,
callbacks=self.callbacks, sudo=options.sudo,