1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Cleanup debug.py (#17222)

* Use isinstance instead of comparing to type.
* Change check against unicode type to check against six.string_types
  for python3 compatibility.
This commit is contained in:
Toshio Kuratomi 2016-08-24 10:37:15 -07:00 committed by GitHub
parent 8ac5896889
commit 5d865ec1ef

View file

@ -1,4 +1,5 @@
# Copyright 2012, Dag Wieers <dag@wieers.com>
# Copyright 2016, Toshio Kuratomi <tkuratomi@ansible.com>
#
# This file is part of Ansible
#
@ -17,15 +18,17 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.compat.six import string_types
from ansible.errors import AnsibleUndefinedVariable
from ansible.plugins.action import ActionBase
from ansible.utils.unicode import to_unicode
from ansible.errors import AnsibleUndefinedVariable
class ActionModule(ActionBase):
''' Print statements during execution '''
TRANSFERS_FILES = False
VALID_ARGS = set(['msg', 'var', 'verbosity'])
VALID_ARGS = frozenset(('msg', 'var', 'verbosity'))
def run(self, tmp=None, task_vars=None):
if task_vars is None:
@ -54,14 +57,14 @@ class ActionModule(ActionBase):
results = self._templar.template(self._task.args['var'], convert_bare=True, fail_on_undefined=True, bare_deprecated=False)
if results == self._task.args['var']:
# if results is not str/unicode type, raise an exception
if type(results) not in [str, unicode]:
if not isinstance(results, string_types):
raise AnsibleUndefinedVariable
# If var name is same as result, try to template it
results = self._templar.template("{{" + results + "}}", convert_bare=True, fail_on_undefined=True)
except AnsibleUndefinedVariable:
results = "VARIABLE IS NOT DEFINED!"
if type(self._task.args['var']) in (list, dict):
if isinstance(self._task.args['var'], (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: