From 35fdf6636b7ab462a6fa11221137b4c4d9b241c4 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 16 Apr 2012 22:15:55 -0400 Subject: [PATCH] Allow --user for playbooks, no need for port setting as can specify in inventory file now. --- bin/ansible | 7 +++---- bin/ansible-playbook | 21 +++++++++++++++------ lib/ansible/playbook.py | 6 ++++-- lib/ansible/utils.py | 7 +------ 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/bin/ansible b/bin/ansible index 844004ecc4d..b9a393f21bd 100755 --- a/bin/ansible +++ b/bin/ansible @@ -47,7 +47,7 @@ class Cli(object): def parse(self): ''' create an options parser for bin/ansible ''' - parser = utils.base_parser(constants=C, port_opts=True, runas_opts=True, async_opts=True, + parser = utils.base_parser(constants=C, runas_opts=True, async_opts=True, output_opts=True, connect_opts=True, usage='%prog [options]') parser.add_option('-a', '--args', dest='module_args', help="module arguments", default=C.DEFAULT_MODULE_ARGS) @@ -87,7 +87,7 @@ class Cli(object): module_args=options.module_args, remote_user=options.remote_user, remote_pass=sshpass, host_list=options.inventory, timeout=options.timeout, - remote_port=options.remote_port, forks=options.forks, + forks=options.forks, background=options.seconds, pattern=pattern, callbacks=self.callbacks, sudo=options.sudo, sudo_pass=sudopass, verbose=True, @@ -104,8 +104,7 @@ class Cli(object): module_args="jid=%s" % jid, remote_user=old_runner.remote_user, remote_pass=old_runner.remote_pass, inventory=old_runner.inventory, timeout=old_runner.timeout, forks=old_runner.forks, - remote_port=old_runner.remote_port, pattern='*', - callbacks=self.silent_callbacks, verbose=True, + pattern='*', callbacks=self.silent_callbacks, verbose=True, ) # ---------------------------------------------- diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 9542e34b9ff..a84b30705cc 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -33,7 +33,7 @@ def main(args): # create parser for CLI options usage = "%prog playbook.yml" - parser = utils.base_parser(constants=C, usage=usage, connect_opts=True) + parser = utils.base_parser(constants=C, usage=usage, connect_opts=True, runas_opts=True) parser.add_option('-e', '--extra-vars', dest='extra_vars', help='arguments to pass to the inventory script') parser.add_option('-O', '--override-hosts', dest="override_hosts", default=None, @@ -63,13 +63,22 @@ def main(args): runner_cb = callbacks.PlaybookRunnerCallbacks(stats) pb = ansible.playbook.PlayBook( - playbook=playbook,module_path=options.module_path, - host_list=options.inventory, override_hosts=override_hosts, + playbook=playbook, + module_path=options.module_path, + host_list=options.inventory, + override_hosts=override_hosts, extra_vars=options.extra_vars, - forks=options.forks, debug=options.debug, verbose=True, + forks=options.forks, + debug=options.debug, + verbose=True, + remote_user=options.remote_user, remote_pass=sshpass, - callbacks=playbook_cb, runner_callbacks=runner_cb, stats=stats, - timeout=options.timeout, transport=options.connection, + callbacks=playbook_cb, + runner_callbacks=runner_cb, + stats=stats, + timeout=options.timeout, + transport=options.connection, + sudo=options.sudo, sudo_pass=sudopass ) try: diff --git a/lib/ansible/playbook.py b/lib/ansible/playbook.py index c5c843c9fdb..4df28389f03 100755 --- a/lib/ansible/playbook.py +++ b/lib/ansible/playbook.py @@ -64,7 +64,8 @@ class PlayBook(object): verbose = False, callbacks = None, runner_callbacks = None, - stats = None): + stats = None, + sudo = False): if playbook is None or callbacks is None or runner_callbacks is None or stats is None: raise Exception('missing required arguments') @@ -83,6 +84,7 @@ class PlayBook(object): self.override_hosts = override_hosts self.extra_vars = extra_vars self.stats = stats + self.sudo = sudo self.sudo_pass = sudo_pass self.basedir = os.path.dirname(playbook) @@ -529,7 +531,7 @@ class PlayBook(object): handlers = pg.get('handlers', []) user = pg.get('user', self.remote_user) port = pg.get('port', self.remote_port) - sudo = pg.get('sudo', False) + sudo = pg.get('sudo', self.sudo) transport = pg.get('connection', self.transport) self.callbacks.on_play_start(pattern) diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index bcbb5904fd7..d1bb9490e68 100755 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -279,7 +279,7 @@ class SortedOptParser(optparse.OptionParser): self.option_list.sort(key=methodcaller('get_opt_string')) return optparse.OptionParser.format_help(self, formatter=None) -def base_parser(constants=C, usage="", output_opts=False, port_opts=False, runas_opts=False, async_opts=False, connect_opts=False): +def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, async_opts=False, connect_opts=False): ''' create an options parser for any ansible script ''' parser = SortedOptParser(usage) @@ -301,11 +301,6 @@ def base_parser(constants=C, usage="", output_opts=False, port_opts=False, runas dest='timeout', help="override the SSH timeout in seconds (default=%s)" % constants.DEFAULT_TIMEOUT) - if port_opts: - parser.add_option('-p', '--port', default=constants.DEFAULT_REMOTE_PORT, type='int', - dest='remote_port', - help="override the remote ssh port (default=%s)" % constants.DEFAULT_REMOTE_PORT) - if output_opts: parser.add_option('-o', '--one-line', dest='one_line', action='store_true', help='condense output')