diff options
-rw-r--r-- | filter_plugins/oo_filters.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py index 1c12f2e07..39e6b0a0b 100644 --- a/filter_plugins/oo_filters.py +++ b/filter_plugins/oo_filters.py @@ -17,9 +17,17 @@ import re import json import yaml from ansible.parsing.yaml.dumper import AnsibleDumper -from ansible.utils.unicode import to_unicode from urlparse import urlparse +try: + # ansible-2.2 + # ansible.utils.unicode.to_unicode is deprecated in ansible-2.2, + # ansible.module_utils._text.to_text should be used instead. + from ansible.module_utils._text import to_text +except ImportError: + # ansible-2.1 + from ansible.utils.unicode import to_unicode as to_text + # Disabling too-many-public-methods, since filter methods are necessarily # public # pylint: disable=too-many-public-methods @@ -626,7 +634,7 @@ class FilterModule(object): default_flow_style=False, Dumper=AnsibleDumper, **kw) padded = "\n".join([" " * level * indent + line for line in transformed.splitlines()]) - return to_unicode("\n{0}".format(padded)) + return to_text("\n{0}".format(padded)) except Exception as my_e: raise errors.AnsibleFilterError('Failed to convert: %s' % my_e) |