From a40ac93716fee4d0716a8d23d11f5489df49bd55 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Tue, 28 Feb 2012 04:20:25 -0500 Subject: [PATCH] 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 --- bin/ansible | 24 +++++++++++++++++------ lib/ansible/scripts.py | 43 ------------------------------------------ 2 files changed, 18 insertions(+), 49 deletions(-) delete mode 100644 lib/ansible/scripts.py diff --git a/bin/ansible b/bin/ansible index f08ae59ae9..1591e28b63 100755 --- a/bin/ansible +++ b/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() diff --git a/lib/ansible/scripts.py b/lib/ansible/scripts.py deleted file mode 100644 index 062b0fa029..0000000000 --- a/lib/ansible/scripts.py +++ /dev/null @@ -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 . -# - -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 -