mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
allow skipping debug depending on verbosity
This commit is contained in:
parent
fe09f7ee49
commit
5552c04976
1 changed files with 26 additions and 18 deletions
|
@ -26,7 +26,7 @@ class ActionModule(ActionBase):
|
||||||
''' Print statements during execution '''
|
''' Print statements during execution '''
|
||||||
|
|
||||||
TRANSFERS_FILES = False
|
TRANSFERS_FILES = False
|
||||||
VALID_ARGS = set(['msg', 'var'])
|
VALID_ARGS = set(['msg', 'var', 'verbosity'])
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
if task_vars is None:
|
if task_vars is None:
|
||||||
|
@ -41,26 +41,34 @@ class ActionModule(ActionBase):
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
result = super(ActionModule, self).run(tmp, task_vars)
|
||||||
|
|
||||||
if 'msg' in self._task.args:
|
verbosity = 0
|
||||||
result['msg'] = self._task.args['msg']
|
# get task verbosity
|
||||||
|
if 'verbosity' in self._task.args:
|
||||||
|
verbosity = int(self._task.args['verbosity'])
|
||||||
|
|
||||||
elif 'var' in self._task.args:
|
if verbosity <= self._display.verbosity:
|
||||||
try:
|
if 'msg' in self._task.args:
|
||||||
results = self._templar.template(self._task.args['var'], convert_bare=True, fail_on_undefined=True, bare_deprecated=False)
|
result['msg'] = self._task.args['msg']
|
||||||
if results == self._task.args['var']:
|
|
||||||
raise AnsibleUndefinedVariable
|
|
||||||
except AnsibleUndefinedVariable:
|
|
||||||
results = "VARIABLE IS NOT DEFINED!"
|
|
||||||
|
|
||||||
if type(self._task.args['var']) in (list, dict):
|
elif 'var' in self._task.args:
|
||||||
# If var is a list or dict, use the type as key to display
|
try:
|
||||||
result[to_unicode(type(self._task.args['var']))] = results
|
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:
|
else:
|
||||||
result[self._task.args['var']] = results
|
result['msg'] = 'Hello world!'
|
||||||
else:
|
|
||||||
result['msg'] = 'Hello world!'
|
|
||||||
|
|
||||||
# force flag to make debug output module always verbose
|
# force flag to make debug output module always verbose
|
||||||
result['_ansible_verbose_always'] = True
|
result['_ansible_verbose_always'] = True
|
||||||
|
else:
|
||||||
|
result['skipped'] = True
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue