mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
add --list-hosts support to bin/ansible
add error handling when no arg passed to command module
This commit is contained in:
parent
637883164e
commit
8655f64e68
1 changed files with 11 additions and 0 deletions
11
bin/ansible
11
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
|
||||
|
|
Loading…
Reference in a new issue