diff --git a/lib/ansible/parsing/yaml/dumper.py b/lib/ansible/parsing/yaml/dumper.py index dc498acd066..3c7bd3120be 100644 --- a/lib/ansible/parsing/yaml/dumper.py +++ b/lib/ansible/parsing/yaml/dumper.py @@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type import yaml +from six import PY3 from ansible.parsing.yaml.objects import AnsibleUnicode @@ -30,8 +31,13 @@ class AnsibleDumper(yaml.SafeDumper): ''' pass +if PY3: + represent_unicode = yaml.representer.SafeRepresenter.represent_str +else: + represent_unicode = yaml.representer.SafeRepresenter.represent_unicode + AnsibleDumper.add_representer( AnsibleUnicode, - yaml.representer.SafeRepresenter.represent_unicode + represent_unicode, )