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.
pull/603/head
Michael DeHaan 13 years ago
parent 9efea6f7a2
commit efac68b636

@ -96,7 +96,7 @@ class Cli(object):
pattern=pattern, pattern=pattern,
callbacks=self.callbacks, sudo=options.sudo, callbacks=self.callbacks, sudo=options.sudo,
sudo_pass=sudopass,sudo_user=options.sudo_user, sudo_pass=sudopass,sudo_user=options.sudo_user,
transport=options.connection, debug=options.debug transport=options.connection, verbose=options.verbose
) )
if options.seconds: if options.seconds:

@ -58,15 +58,15 @@ def main(args):
for playbook in args: for playbook in args:
stats = callbacks.AggregateStats() stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks() playbook_cb = callbacks.PlaybookCallbacks(verbose=options.verbose)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats) runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=options.verbose)
pb = ansible.playbook.PlayBook( pb = ansible.playbook.PlayBook(
playbook=playbook, playbook=playbook,
module_path=options.module_path, module_path=options.module_path,
host_list=options.inventory, host_list=options.inventory,
forks=options.forks, forks=options.forks,
debug=options.debug, verbose=options.verbose,
remote_user=options.remote_user, remote_user=options.remote_user,
remote_pass=sshpass, remote_pass=sshpass,
callbacks=playbook_cb, callbacks=playbook_cb,

@ -2,12 +2,12 @@
.\" Title: ansible-playbook .\" Title: ansible-playbook
.\" Author: [see the "AUTHOR" section] .\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/> .\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" Date: 05/25/2012 .\" Date: 06/19/2012
.\" Manual: System administration commands .\" Manual: System administration commands
.\" Source: Ansible 0.5 .\" Source: Ansible 0.5
.\" Language: English .\" 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 .\" * set default formatting
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
@ -34,9 +34,9 @@ The names of one or more YAML format files to run as ansible playbooks\&.
.RE .RE
.SH "OPTIONS" .SH "OPTIONS"
.sp .sp
\fB\-D\fR, \fB\-\-debug\fR \fB\-v\fR, \fB\-\-verbose\fR
.sp .sp
Debug mode Verbose mode, more output from successful actions will be shown
.PP .PP
\fB\-i\fR \fIPATH\fR, \fB\-\-inventory=\fR\fIPATH\fR \fB\-i\fR \fIPATH\fR, \fB\-\-inventory=\fR\fIPATH\fR
.RS 4 .RS 4

@ -34,9 +34,9 @@ The names of one or more YAML format files to run as ansible playbooks.
OPTIONS OPTIONS
------- -------
*-D*, *--debug* *-v*, *--verbose*
Debug mode Verbose mode, more output from successful actions will be shown
*-i* 'PATH', *--inventory=*'PATH':: *-i* 'PATH', *--inventory=*'PATH'::

@ -2,12 +2,12 @@
.\" Title: ansible .\" Title: ansible
.\" Author: [see the "AUTHOR" section] .\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/> .\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" Date: 05/25/2012 .\" Date: 06/19/2012
.\" Manual: System administration commands .\" Manual: System administration commands
.\" Source: Ansible 0.5 .\" Source: Ansible 0.5
.\" Language: English .\" 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 .\" * set default formatting
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
@ -70,11 +70,6 @@ The
to pass to the module\&. to pass to the module\&.
.RE .RE
.PP .PP
\fB\-D\fR, \fB\-\-debug\fR
.RS 4
Debug mode
.RE
.PP
\fB\-k\fR, \fB\-\-ask\-pass\fR \fB\-k\fR, \fB\-\-ask\-pass\fR
.RS 4 .RS 4
Prompt for the SSH password instead of assuming key\-based authentication with ssh\-agent\&. Prompt for the SSH password instead of assuming key\-based authentication with ssh\-agent\&.

@ -60,10 +60,6 @@ The 'DIRECTORY' to load modules from. The default is '/usr/share/ansible'.
The 'ARGUMENTS' to pass to the module. The 'ARGUMENTS' to pass to the module.
*-D*, *--debug*::
Debug mode
*-k*, *--ask-pass*:: *-k*, *--ask-pass*::
Prompt for the SSH password instead of assuming key-based authentication with ssh-agent. Prompt for the SSH password instead of assuming key-based authentication with ssh-agent.

@ -132,14 +132,10 @@ class CliRunnerCallbacks(DefaultRunnerCallbacks):
self._async_notified = {} self._async_notified = {}
def on_failed(self, host, res): def on_failed(self, host, res):
invocation = res.get('invocation','') self._on_any(host,res)
if not invocation.startswith('async_status'):
self._on_any(host,res)
def on_ok(self, host, res): def on_ok(self, host, res):
invocation = res.get('invocation','') self._on_any(host,res)
if not invocation.startswith('async_status'):
self._on_any(host,res)
def on_unreachable(self, host, res): def on_unreachable(self, host, res):
if type(res) == dict: if type(res) == dict:
@ -180,28 +176,23 @@ class CliRunnerCallbacks(DefaultRunnerCallbacks):
class PlaybookRunnerCallbacks(DefaultRunnerCallbacks): class PlaybookRunnerCallbacks(DefaultRunnerCallbacks):
''' callbacks used for Runner() from /usr/bin/ansible-playbook ''' ''' callbacks used for Runner() from /usr/bin/ansible-playbook '''
def __init__(self, stats): def __init__(self, stats, verbose=False):
self.stats = stats self.stats = stats
self._async_notified = {} self._async_notified = {}
self.verbose = verbose
def on_unreachable(self, host, msg): def on_unreachable(self, host, msg):
print "fatal: [%s] => %s" % (host, msg) print "fatal: [%s] => %s" % (host, msg)
def on_failed(self, host, results): def on_failed(self, host, results):
invocation = results.get('invocation',None) print "failed: [%s] => %s\n" % (host, utils.smjson(results))
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))
def on_ok(self, host, host_result): def on_ok(self, host, host_result):
invocation = host_result.get('invocation','') # show verbose output for non-setup module results if --verbose is used
if invocation.startswith('async_status'): if not self.verbose or host_result.get("verbose_override",None) is not None:
pass
elif not invocation or invocation.startswith('setup '):
print "ok: [%s]\n" % (host) print "ok: [%s]\n" % (host)
else: else:
print "ok: [%s] => %s\n" % (host, invocation) print "ok: [%s] => %s" % (host, utils.smjson(host_result))
def on_error(self, host, err): def on_error(self, host, err):
print >>sys.stderr, "err: [%s] => %s\n" % (host, err) print >>sys.stderr, "err: [%s] => %s\n" % (host, err)
@ -230,8 +221,8 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks):
class PlaybookCallbacks(object): class PlaybookCallbacks(object):
''' playbook.py callbacks used by /usr/bin/ansible-playbook ''' ''' playbook.py callbacks used by /usr/bin/ansible-playbook '''
def __init__(self): def __init__(self, verbose=False):
pass self.verbose = verbose
def on_start(self): def on_start(self):
print "\n" print "\n"

@ -55,7 +55,7 @@ class PlayBook(object):
remote_port = C.DEFAULT_REMOTE_PORT, remote_port = C.DEFAULT_REMOTE_PORT,
transport = C.DEFAULT_TRANSPORT, transport = C.DEFAULT_TRANSPORT,
private_key_file = C.DEFAULT_PRIVATE_KEY_FILE, private_key_file = C.DEFAULT_PRIVATE_KEY_FILE,
debug = False, verbose = False,
callbacks = None, callbacks = None,
runner_callbacks = None, runner_callbacks = None,
stats = None, stats = None,
@ -95,7 +95,7 @@ class PlayBook(object):
self.remote_pass = remote_pass self.remote_pass = remote_pass
self.remote_port = remote_port self.remote_port = remote_port
self.transport = transport self.transport = transport
self.debug = debug self.verbose = verbose
self.callbacks = callbacks self.callbacks = callbacks
self.runner_callbacks = runner_callbacks self.runner_callbacks = runner_callbacks
self.stats = stats self.stats = stats
@ -166,7 +166,7 @@ class PlayBook(object):
private_key_file=self.private_key_file, private_key_file=self.private_key_file,
setup_cache=self.SETUP_CACHE, basedir=self.basedir, setup_cache=self.SETUP_CACHE, basedir=self.basedir,
conditional=task.only_if, callbacks=self.runner_callbacks, 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 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, 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, 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, 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() ).run()
self.stats.compute(setup_results, setup=True) self.stats.compute(setup_results, setup=True)

@ -111,7 +111,7 @@ class Runner(object):
private_key_file=C.DEFAULT_PRIVATE_KEY_FILE, sudo_pass=C.DEFAULT_SUDO_PASS, private_key_file=C.DEFAULT_PRIVATE_KEY_FILE, sudo_pass=C.DEFAULT_SUDO_PASS,
background=0, basedir=None, setup_cache=None, background=0, basedir=None, setup_cache=None,
transport=C.DEFAULT_TRANSPORT, conditional='True', callbacks=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): module_vars=None, is_playbook=False, inventory=None):
""" """
@ -172,7 +172,7 @@ class Runner(object):
self.module_args = module_args self.module_args = module_args
self.module_vars = module_vars self.module_vars = module_vars
self.timeout = timeout self.timeout = timeout
self.debug = debug self.verbose = verbose
self.remote_user = remote_user self.remote_user = remote_user
self.remote_pass = remote_pass self.remote_pass = remote_pass
self.remote_port = remote_port self.remote_port = remote_port

@ -49,18 +49,12 @@ def exit(msg, rc=1):
def bigjson(result): def bigjson(result):
''' format JSON output (uncompressed) ''' ''' format JSON output (uncompressed) '''
# hide some internals magic from command line userland
result2 = result.copy() result2 = result.copy()
if 'invocation' in result2:
del result2['invocation']
return json.dumps(result2, sort_keys=True, indent=4) return json.dumps(result2, sort_keys=True, indent=4)
def smjson(result): def smjson(result):
''' format JSON output (compressed) ''' ''' format JSON output (compressed) '''
# hide some internals magic from command line userland
result2 = result.copy() result2 = result.copy()
if 'invocation' in result2:
del result2['invocation']
return json.dumps(result2, sort_keys=True) return json.dumps(result2, sort_keys=True)
def task_start_msg(name, conditional): 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 ''' ''' create an options parser for any ansible script '''
parser = SortedOptParser(usage) parser = SortedOptParser(usage)
parser.add_option('-D','--debug', default=False, action="store_true", parser.add_option('-v','--verbose', default=False, action="store_true",
help='debug mode') help='verbose mode')
parser.add_option('-f','--forks', dest='forks', default=constants.DEFAULT_FORKS, type='int', 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) help="specify number of parallel processes to use (default=%s)" % constants.DEFAULT_FORKS)
parser.add_option('-i', '--inventory-file', dest='inventory', parser.add_option('-i', '--inventory-file', dest='inventory',

@ -411,5 +411,8 @@ setup_result['changed'] = changed
setup_result['md5sum'] = md5sum2 setup_result['md5sum'] = md5sum2
setup_result['ansible_facts'] = setup_options 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) print json.dumps(setup_result)

@ -63,7 +63,7 @@ class TestCallbacks(object):
def on_ok(self, host, result): def on_ok(self, host, result):
# delete certain info from host_result to make test comparisons easier # delete certain info from host_result to make test comparisons easier
host_result = result.copy() 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: if k in host_result:
del host_result[k] del host_result[k]
for k in host_result.keys(): for k in host_result.keys():

Loading…
Cancel
Save