From 8655f64e685c072f09974be4a93ff1ec398b43e5 Mon Sep 17 00:00:00 2001 From: "Christopher A. Snapp" Date: Fri, 7 Dec 2012 15:50:25 -0500 Subject: [PATCH] add --list-hosts support to bin/ansible add error handling when no arg passed to command module --- bin/ansible | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bin/ansible b/bin/ansible index 38b74b36709..394d8a79428 100755 --- a/bin/ansible +++ b/bin/ansible @@ -52,6 +52,8 @@ class Cli(object): parser.add_option('-m', '--module-name', dest='module_name', help="module name to execute (default=%s)" % C.DEFAULT_MODULE_NAME, default=C.DEFAULT_MODULE_NAME) + parser.add_option('--list-hosts', dest='listhosts', action='store_true', + help="dump out a list of hosts matching input pattern, does not execute any modules!") options, args = parser.parse_args() self.callbacks.options = options @@ -73,6 +75,15 @@ class Cli(object): print >>sys.stderr, "No hosts matched" sys.exit(1) + if options.listhosts: + for host in hosts: + print ' %s' % host + sys.exit(0) + + if options.module_name == 'command' and not options.module_args: + print >>sys.stderr, "No argument passed to command module" + sys.exit(1) + sshpass = None sudopass = None options.ask_pass = options.ask_pass or C.DEFAULT_ASK_PASS