mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Plan to merge things back into ansible means we can simplify our code tree
by eliminating the lib/ansible/scripts file. Ansible-playbook doesn't have enough options to need it's own thing, and we're going to try to work most things back into bin/ansible
This commit is contained in:
parent
55d256d82a
commit
a40ac93716
2 changed files with 18 additions and 49 deletions
24
bin/ansible
24
bin/ansible
|
@ -26,7 +26,7 @@ import shlex
|
|||
import ansible.runner
|
||||
import ansible.playbook
|
||||
import ansible.constants as C
|
||||
from ansible.scripts import base_ans_parser, error_print
|
||||
from optparse import OptionParser
|
||||
|
||||
class Cli(object):
|
||||
|
||||
|
@ -34,7 +34,19 @@ class Cli(object):
|
|||
pass
|
||||
|
||||
def runner(self):
|
||||
parser = base_ans_parser()
|
||||
parser = OptionParser()
|
||||
parser.add_option("-l", "--host-list", dest="host_list",
|
||||
help="path to hosts list", default=C.DEFAULT_HOST_LIST)
|
||||
parser.add_option("-m", "--module-path", dest="module_path",
|
||||
help="path to module library", default=C.DEFAULT_MODULE_PATH)
|
||||
parser.add_option('-u', '--user', default=C.DEFAULT_REMOTE_USER,
|
||||
dest='remote_user', help='set the default username')
|
||||
parser.add_option("-p", "--pattern", dest="pattern",
|
||||
help="hostname pattern", default=C.DEFAULT_PATTERN)
|
||||
parser.add_option("-k", "--ask-pass", default=False, action="store_true",
|
||||
help="ask the user to input the ssh password for connecting")
|
||||
parser.add_option('-f','--forks', dest='forks', default=C.DEFAULT_FORKS, type='int',
|
||||
help='set the number of forks to start up')
|
||||
parser.add_option("-n", "--name", dest="module_name",
|
||||
help="module name to execute", default=None)
|
||||
parser.add_option("-a", "--args", dest="module_args",
|
||||
|
@ -125,7 +137,7 @@ class Cli(object):
|
|||
msg += traceback
|
||||
if error:
|
||||
msg += error
|
||||
error_print(msg)
|
||||
print >> sys.stderr, msg
|
||||
continue
|
||||
|
||||
if options.one_line:
|
||||
|
@ -159,11 +171,11 @@ class Cli(object):
|
|||
print json.dumps(result, indent=4, sort_keys=True)
|
||||
|
||||
if len(results['dark'].keys()) > 0:
|
||||
error_print('*** Hosts which could not be contacted or did not respond: ***')
|
||||
print >> sys.stderr, "*** Hosts which could not be contacted or did not respond: ***"
|
||||
failed_hosts = results['dark'].keys()
|
||||
for hostname in failed_hosts:
|
||||
error_print("%s:\n%s\n" % (hostname, results['dark'][hostname]))
|
||||
print ''
|
||||
print >> sys.stderr, "%s:\n%s\n" % (hostname, results['dark'][hostname])
|
||||
print ""
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli = Cli()
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from optparse import OptionParser
|
||||
import sys
|
||||
import constants as C
|
||||
|
||||
def base_ans_parser():
|
||||
parser = OptionParser()
|
||||
parser.add_option("-l", "--host-list", dest="host_list",
|
||||
help="path to hosts list", default=C.DEFAULT_HOST_LIST)
|
||||
parser.add_option("-m", "--module-path", dest="module_path",
|
||||
help="path to module library", default=C.DEFAULT_MODULE_PATH)
|
||||
parser.add_option('-u', '--user', default=C.DEFAULT_REMOTE_USER,
|
||||
dest='remote_user', help='set the default username')
|
||||
parser.add_option("-p", "--pattern", dest="pattern",
|
||||
help="hostname pattern", default=C.DEFAULT_PATTERN)
|
||||
parser.add_option("-k", "--ask-pass", default=False, action="store_true",
|
||||
help="ask the user to input the ssh password for connecting")
|
||||
parser.add_option('-f','--forks', dest='forks', default=C.DEFAULT_FORKS, type='int',
|
||||
help='set the number of forks to start up')
|
||||
return parser
|
||||
|
||||
# other functions as needed for nicely handling output from json back
|
||||
# to things people might be more inclined to deal with at a bash prompt
|
||||
|
||||
|
||||
def error_print(msg):
|
||||
print >> sys.stderr, msg
|
||||
|
Loading…
Reference in a new issue