From c46a09dcf440c92796c7686371a2e6e5835ed011 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 16 Jan 2019 13:22:07 -0800 Subject: [PATCH] Fix UnicodeEncodeError for ansible --version. (#50997) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error occurs on Python 2.x when running the following commands: ``` mkdir /tmp/Δ.cfg ANSIBLE_CONFIG=/tmp/Δ.cfg ansible --version | tee ``` --- lib/ansible/cli/arguments/optparse_helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/cli/arguments/optparse_helpers.py b/lib/ansible/cli/arguments/optparse_helpers.py index e933af2133..d9278bb215 100644 --- a/lib/ansible/cli/arguments/optparse_helpers.py +++ b/lib/ansible/cli/arguments/optparse_helpers.py @@ -15,6 +15,7 @@ import yaml import ansible from ansible import constants as C from ansible.module_utils.six import string_types +from ansible.module_utils._text import to_native from ansible.release import __version__ from ansible.utils.path import unfrackpath @@ -192,7 +193,7 @@ def create_base_parser(usage="", desc=None, epilog=None): Create an options parser for all ansible scripts """ # base opts - parser = SortedOptParser(usage, version=version("%prog"), description=desc, epilog=epilog) + parser = SortedOptParser(usage, version=to_native(version("%prog")), description=desc, epilog=epilog) parser.remove_option('--version') version_help = "show program's version number, config file location, configured module search path," \ " module location, executable location and exit"