Skip to content

Commit

Permalink
Support unicode output when dumping yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
mtnbikenc committed Apr 3, 2017
1 parent 0bac74c commit 203630f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
21 changes: 12 additions & 9 deletions filter_plugins/oo_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
import yaml

from ansible import errors
# pylint no-name-in-module and import-error disabled here because pylint
# fails to properly detect the packages when installed in a virtualenv
from ansible.compat.six import string_types # pylint:disable=no-name-in-module,import-error
from ansible.compat.six.moves.urllib.parse import urlparse # pylint:disable=no-name-in-module,import-error
from ansible.module_utils._text import to_text
from ansible.parsing.yaml.dumper import AnsibleDumper

# ansible.compat.six goes away with Ansible 2.4
try:
from ansible.compat.six import string_types, u
from ansible.compat.six.moves.urllib.parse import urlparse
except ImportError:
from ansible.module_utils.six import string_types, u
from ansible.module_utils.six.moves.urllib.parse import urlparse

HAS_OPENSSL = False
try:
import OpenSSL.crypto
Expand Down Expand Up @@ -655,11 +658,11 @@ def to_padded_yaml(data, level=0, indent=2, **kw):
return ""

try:
transformed = yaml.dump(data, indent=indent, allow_unicode=True,
default_flow_style=False,
Dumper=AnsibleDumper, **kw)
transformed = u(yaml.dump(data, indent=indent, allow_unicode=True,
default_flow_style=False,
Dumper=AnsibleDumper, **kw))
padded = "\n".join([" " * level * indent + line for line in transformed.splitlines()])
return to_text("\n{0}".format(padded))
return "\n{0}".format(padded)
except Exception as my_e:
raise errors.AnsibleFilterError('Failed to convert: %s' % my_e)

Expand Down
17 changes: 10 additions & 7 deletions roles/openshift_master_facts/filter_plugins/openshift_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
from ansible import errors
from ansible.parsing.yaml.dumper import AnsibleDumper
from ansible.plugins.filter.core import to_bool as ansible_bool
# pylint import-error disabled because pylint cannot find the package
# when installed in a virtualenv
from ansible.compat.six import string_types # pylint: disable=no-name-in-module,import-error

# ansible.compat.six goes away with Ansible 2.4
try:
from ansible.compat.six import string_types, u
except ImportError:
from ansible.module_utils.six import string_types, u

import yaml

Expand Down Expand Up @@ -490,10 +493,10 @@ def translate_idps(idps, api_version, openshift_version, deployment_type):
idp_list.append(idp_inst)

IdentityProviderBase.validate_idp_list(idp_list, openshift_version, deployment_type)
return yaml.dump([idp.to_dict() for idp in idp_list],
allow_unicode=True,
default_flow_style=False,
Dumper=AnsibleDumper)
return u(yaml.dump([idp.to_dict() for idp in idp_list],
allow_unicode=True,
default_flow_style=False,
Dumper=AnsibleDumper))

@staticmethod
def validate_pcs_cluster(data, masters=None):
Expand Down
14 changes: 10 additions & 4 deletions utils/src/ooinstall/ansible_plugins/facts_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
from ansible.plugins.callback import CallbackBase
from ansible.parsing.yaml.dumper import AnsibleDumper

# ansible.compat.six goes away with Ansible 2.4
try:
from ansible.compat.six import u
except ImportError:
from ansible.module_utils.six import u


# pylint: disable=super-init-not-called
class CallbackModule(CallbackBase):
Expand Down Expand Up @@ -39,10 +45,10 @@ def v2_runner_on_ok(self, res):
facts = abridged_result['result']['ansible_facts']['openshift']
hosts_yaml = {}
hosts_yaml[res._host.get_name()] = facts
to_dump = yaml.dump(hosts_yaml,
allow_unicode=True,
default_flow_style=False,
Dumper=AnsibleDumper)
to_dump = u(yaml.dump(hosts_yaml,
allow_unicode=True,
default_flow_style=False,
Dumper=AnsibleDumper))
os.write(self.hosts_yaml, to_dump)

def v2_runner_on_skipped(self, res):
Expand Down

0 comments on commit 203630f

Please sign in to comment.