Skip to content

Commit

Permalink
allow skipping debug depending on verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoca committed Feb 18, 2016
1 parent fe09f7e commit 5552c04
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions lib/ansible/plugins/action/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ActionModule(ActionBase):
''' Print statements during execution '''

TRANSFERS_FILES = False
VALID_ARGS = set(['msg', 'var'])
VALID_ARGS = set(['msg', 'var', 'verbosity'])

def run(self, tmp=None, task_vars=None):
if task_vars is None:
Expand All @@ -41,26 +41,34 @@ def run(self, tmp=None, task_vars=None):

result = super(ActionModule, self).run(tmp, task_vars)

if 'msg' in self._task.args:
result['msg'] = self._task.args['msg']
verbosity = 0
# get task verbosity
if 'verbosity' in self._task.args:
verbosity = int(self._task.args['verbosity'])

elif 'var' in self._task.args:
try:
results = self._templar.template(self._task.args['var'], convert_bare=True, fail_on_undefined=True, bare_deprecated=False)
if results == self._task.args['var']:
raise AnsibleUndefinedVariable
except AnsibleUndefinedVariable:
results = "VARIABLE IS NOT DEFINED!"
if verbosity <= self._display.verbosity:
if 'msg' in self._task.args:
result['msg'] = self._task.args['msg']

if type(self._task.args['var']) in (list, dict):
# If var is a list or dict, use the type as key to display
result[to_unicode(type(self._task.args['var']))] = results
elif 'var' in self._task.args:
try:
results = self._templar.template(self._task.args['var'], convert_bare=True, fail_on_undefined=True, bare_deprecated=False)
if results == self._task.args['var']:
raise AnsibleUndefinedVariable
except AnsibleUndefinedVariable:
results = "VARIABLE IS NOT DEFINED!"

if type(self._task.args['var']) in (list, dict):
# If var is a list or dict, use the type as key to display
result[to_unicode(type(self._task.args['var']))] = results
else:
result[self._task.args['var']] = results
else:
result[self._task.args['var']] = results
else:
result['msg'] = 'Hello world!'
result['msg'] = 'Hello world!'

# force flag to make debug output module always verbose
result['_ansible_verbose_always'] = True
# force flag to make debug output module always verbose
result['_ansible_verbose_always'] = True
else:
result['skipped'] = True

return result

0 comments on commit 5552c04

Please sign in to comment.