From efac68b636ed60fb3b751a4fa152da4accd19ac0 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Tue, 19 Jun 2012 21:55:57 -0400 Subject: [PATCH] Remove the -D module debug flag, which no longer is functional due to sudo pty requirements, and replace with -v/--verbose. This flag will show playbook output from non-failing commands. -v is also added to /usr/bin/ansible, but not yet used. I also gutted some internals code dealing with 'invocations' which allowed the callback to know what module invoked it. This is not something 0.5 does or needed, so callbacks have been simplified. --- bin/ansible | 2 +- bin/ansible-playbook | 6 ++-- docs/man/man1/ansible-playbook.1 | 8 +++--- docs/man/man1/ansible-playbook.1.asciidoc.in | 4 +-- docs/man/man1/ansible.1 | 9 ++---- docs/man/man1/ansible.1.asciidoc.in | 4 --- lib/ansible/callbacks.py | 29 +++++++------------- lib/ansible/playbook/__init__.py | 8 +++--- lib/ansible/runner/__init__.py | 4 +-- lib/ansible/utils.py | 10 ++----- library/setup | 3 ++ test/TestPlayBook.py | 2 +- 12 files changed, 34 insertions(+), 55 deletions(-) diff --git a/bin/ansible b/bin/ansible index 5304ac3c7f..fd87a40d36 100755 --- a/bin/ansible +++ b/bin/ansible @@ -96,7 +96,7 @@ class Cli(object): pattern=pattern, callbacks=self.callbacks, sudo=options.sudo, sudo_pass=sudopass,sudo_user=options.sudo_user, - transport=options.connection, debug=options.debug + transport=options.connection, verbose=options.verbose ) if options.seconds: diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 8df340df4e..0e44ffe592 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -58,15 +58,15 @@ def main(args): for playbook in args: stats = callbacks.AggregateStats() - playbook_cb = callbacks.PlaybookCallbacks() - runner_cb = callbacks.PlaybookRunnerCallbacks(stats) + playbook_cb = callbacks.PlaybookCallbacks(verbose=options.verbose) + runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=options.verbose) pb = ansible.playbook.PlayBook( playbook=playbook, module_path=options.module_path, host_list=options.inventory, forks=options.forks, - debug=options.debug, + verbose=options.verbose, remote_user=options.remote_user, remote_pass=sshpass, callbacks=playbook_cb, diff --git a/docs/man/man1/ansible-playbook.1 b/docs/man/man1/ansible-playbook.1 index 4411b79906..eb3ba53ab0 100644 --- a/docs/man/man1/ansible-playbook.1 +++ b/docs/man/man1/ansible-playbook.1 @@ -2,12 +2,12 @@ .\" Title: ansible-playbook .\" Author: [see the "AUTHOR" section] .\" Generator: DocBook XSL Stylesheets v1.75.2 -.\" Date: 05/25/2012 +.\" Date: 06/19/2012 .\" Manual: System administration commands .\" Source: Ansible 0.5 .\" Language: English .\" -.TH "ANSIBLE\-PLAYBOOK" "1" "05/25/2012" "Ansible 0\&.5" "System administration commands" +.TH "ANSIBLE\-PLAYBOOK" "1" "06/19/2012" "Ansible 0\&.5" "System administration commands" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -34,9 +34,9 @@ The names of one or more YAML format files to run as ansible playbooks\&. .RE .SH "OPTIONS" .sp -\fB\-D\fR, \fB\-\-debug\fR +\fB\-v\fR, \fB\-\-verbose\fR .sp -Debug mode +Verbose mode, more output from successful actions will be shown .PP \fB\-i\fR \fIPATH\fR, \fB\-\-inventory=\fR\fIPATH\fR .RS 4 diff --git a/docs/man/man1/ansible-playbook.1.asciidoc.in b/docs/man/man1/ansible-playbook.1.asciidoc.in index 527ae091d1..377dcef532 100644 --- a/docs/man/man1/ansible-playbook.1.asciidoc.in +++ b/docs/man/man1/ansible-playbook.1.asciidoc.in @@ -34,9 +34,9 @@ The names of one or more YAML format files to run as ansible playbooks. OPTIONS ------- -*-D*, *--debug* +*-v*, *--verbose* -Debug mode +Verbose mode, more output from successful actions will be shown *-i* 'PATH', *--inventory=*'PATH':: diff --git a/docs/man/man1/ansible.1 b/docs/man/man1/ansible.1 index 31bfe865b7..0554ebdc9b 100644 --- a/docs/man/man1/ansible.1 +++ b/docs/man/man1/ansible.1 @@ -2,12 +2,12 @@ .\" Title: ansible .\" Author: [see the "AUTHOR" section] .\" Generator: DocBook XSL Stylesheets v1.75.2 -.\" Date: 05/25/2012 +.\" Date: 06/19/2012 .\" Manual: System administration commands .\" Source: Ansible 0.5 .\" Language: English .\" -.TH "ANSIBLE" "1" "05/25/2012" "Ansible 0\&.5" "System administration commands" +.TH "ANSIBLE" "1" "06/19/2012" "Ansible 0\&.5" "System administration commands" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -70,11 +70,6 @@ The to pass to the module\&. .RE .PP -\fB\-D\fR, \fB\-\-debug\fR -.RS 4 -Debug mode -.RE -.PP \fB\-k\fR, \fB\-\-ask\-pass\fR .RS 4 Prompt for the SSH password instead of assuming key\-based authentication with ssh\-agent\&. diff --git a/docs/man/man1/ansible.1.asciidoc.in b/docs/man/man1/ansible.1.asciidoc.in index f01dc549e5..794844fceb 100644 --- a/docs/man/man1/ansible.1.asciidoc.in +++ b/docs/man/man1/ansible.1.asciidoc.in @@ -60,10 +60,6 @@ The 'DIRECTORY' to load modules from. The default is '/usr/share/ansible'. The 'ARGUMENTS' to pass to the module. -*-D*, *--debug*:: - -Debug mode - *-k*, *--ask-pass*:: Prompt for the SSH password instead of assuming key-based authentication with ssh-agent. diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index c981aabb7e..8921a99423 100644 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -132,14 +132,10 @@ class CliRunnerCallbacks(DefaultRunnerCallbacks): self._async_notified = {} def on_failed(self, host, res): - invocation = res.get('invocation','') - if not invocation.startswith('async_status'): - self._on_any(host,res) + self._on_any(host,res) def on_ok(self, host, res): - invocation = res.get('invocation','') - if not invocation.startswith('async_status'): - self._on_any(host,res) + self._on_any(host,res) def on_unreachable(self, host, res): if type(res) == dict: @@ -180,28 +176,23 @@ class CliRunnerCallbacks(DefaultRunnerCallbacks): class PlaybookRunnerCallbacks(DefaultRunnerCallbacks): ''' callbacks used for Runner() from /usr/bin/ansible-playbook ''' - def __init__(self, stats): + def __init__(self, stats, verbose=False): self.stats = stats self._async_notified = {} + self.verbose = verbose def on_unreachable(self, host, msg): print "fatal: [%s] => %s" % (host, msg) def on_failed(self, host, results): - invocation = results.get('invocation',None) - if not invocation or invocation.startswith('setup ') or invocation.startswith('async_status '): - print "failed: [%s] => %s\n" % (host, utils.smjson(results)) - else: - print "failed: [%s] => %s => %s\n" % (host, invocation, utils.smjson(results)) + print "failed: [%s] => %s\n" % (host, utils.smjson(results)) def on_ok(self, host, host_result): - invocation = host_result.get('invocation','') - if invocation.startswith('async_status'): - pass - elif not invocation or invocation.startswith('setup '): + # show verbose output for non-setup module results if --verbose is used + if not self.verbose or host_result.get("verbose_override",None) is not None: print "ok: [%s]\n" % (host) else: - print "ok: [%s] => %s\n" % (host, invocation) + print "ok: [%s] => %s" % (host, utils.smjson(host_result)) def on_error(self, host, err): print >>sys.stderr, "err: [%s] => %s\n" % (host, err) @@ -230,8 +221,8 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks): class PlaybookCallbacks(object): ''' playbook.py callbacks used by /usr/bin/ansible-playbook ''' - def __init__(self): - pass + def __init__(self, verbose=False): + self.verbose = verbose def on_start(self): print "\n" diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 4e9e5dbd3c..738e38f9ba 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -55,7 +55,7 @@ class PlayBook(object): remote_port = C.DEFAULT_REMOTE_PORT, transport = C.DEFAULT_TRANSPORT, private_key_file = C.DEFAULT_PRIVATE_KEY_FILE, - debug = False, + verbose = False, callbacks = None, runner_callbacks = None, stats = None, @@ -95,7 +95,7 @@ class PlayBook(object): self.remote_pass = remote_pass self.remote_port = remote_port self.transport = transport - self.debug = debug + self.verbose = verbose self.callbacks = callbacks self.runner_callbacks = runner_callbacks self.stats = stats @@ -166,7 +166,7 @@ class PlayBook(object): private_key_file=self.private_key_file, setup_cache=self.SETUP_CACHE, basedir=self.basedir, conditional=task.only_if, callbacks=self.runner_callbacks, - debug=self.debug, sudo=task.play.sudo, sudo_user=task.play.sudo_user, + verbose=self.verbose, sudo=task.play.sudo, sudo_user=task.play.sudo_user, transport=task.play.transport, sudo_pass=self.sudo_pass, is_playbook=True ) @@ -256,7 +256,7 @@ class PlayBook(object): forks=self.forks, module_path=self.module_path, timeout=self.timeout, remote_user=play.remote_user, remote_pass=self.remote_pass, remote_port=play.remote_port, private_key_file=self.private_key_file, setup_cache=self.SETUP_CACHE, callbacks=self.runner_callbacks, sudo=play.sudo, sudo_user=play.sudo_user, - debug=self.debug, transport=play.transport, sudo_pass=self.sudo_pass, is_playbook=True + verbose=self.verbose, transport=play.transport, sudo_pass=self.sudo_pass, is_playbook=True ).run() self.stats.compute(setup_results, setup=True) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index b5217badcb..075a9fba83 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -111,7 +111,7 @@ class Runner(object): private_key_file=C.DEFAULT_PRIVATE_KEY_FILE, sudo_pass=C.DEFAULT_SUDO_PASS, background=0, basedir=None, setup_cache=None, transport=C.DEFAULT_TRANSPORT, conditional='True', callbacks=None, - debug=False, sudo=False, sudo_user=C.DEFAULT_SUDO_USER, + verbose=False, sudo=False, sudo_user=C.DEFAULT_SUDO_USER, module_vars=None, is_playbook=False, inventory=None): """ @@ -172,7 +172,7 @@ class Runner(object): self.module_args = module_args self.module_vars = module_vars self.timeout = timeout - self.debug = debug + self.verbose = verbose self.remote_user = remote_user self.remote_pass = remote_pass self.remote_port = remote_port diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index ee87cc7278..65650d2adf 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -49,18 +49,12 @@ def exit(msg, rc=1): def bigjson(result): ''' format JSON output (uncompressed) ''' - # hide some internals magic from command line userland result2 = result.copy() - if 'invocation' in result2: - del result2['invocation'] return json.dumps(result2, sort_keys=True, indent=4) def smjson(result): ''' format JSON output (compressed) ''' - # hide some internals magic from command line userland result2 = result.copy() - if 'invocation' in result2: - del result2['invocation'] return json.dumps(result2, sort_keys=True) def task_start_msg(name, conditional): @@ -324,8 +318,8 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, asyn ''' create an options parser for any ansible script ''' parser = SortedOptParser(usage) - parser.add_option('-D','--debug', default=False, action="store_true", - help='debug mode') + parser.add_option('-v','--verbose', default=False, action="store_true", + help='verbose mode') parser.add_option('-f','--forks', dest='forks', default=constants.DEFAULT_FORKS, type='int', help="specify number of parallel processes to use (default=%s)" % constants.DEFAULT_FORKS) parser.add_option('-i', '--inventory-file', dest='inventory', diff --git a/library/setup b/library/setup index 52c7e62328..fb181c9348 100755 --- a/library/setup +++ b/library/setup @@ -411,5 +411,8 @@ setup_result['changed'] = changed setup_result['md5sum'] = md5sum2 setup_result['ansible_facts'] = setup_options +# hack to keep --verbose from showing all the setup module results +setup_result['verbose_override'] = True + print json.dumps(setup_result) diff --git a/test/TestPlayBook.py b/test/TestPlayBook.py index ec72f261e1..64d26a7ce9 100644 --- a/test/TestPlayBook.py +++ b/test/TestPlayBook.py @@ -63,7 +63,7 @@ class TestCallbacks(object): def on_ok(self, host, result): # delete certain info from host_result to make test comparisons easier host_result = result.copy() - for k in [ 'ansible_job_id', 'results_file', 'invocation', 'md5sum', 'delta', 'start', 'end' ]: + for k in [ 'ansible_job_id', 'results_file', 'md5sum', 'delta', 'start', 'end' ]: if k in host_result: del host_result[k] for k in host_result.keys():