diff options
author | Matt Martz <matt@sivel.net> | 2021-03-08 04:29:58 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 04:29:58 -0600 |
commit | 65037d4781b028675f60a8f99704e6b1862987c1 (patch) | |
tree | 5a7212e58176778acc9924d9272a93d9e81b356d | |
parent | ebe0ed93315702ec4855449ad3e9243b83f7cbe0 (diff) | |
download | ansible-65037d4781b028675f60a8f99704e6b1862987c1.tar.gz |
[stable-2.10] Normalize ConfigParser between Python2 and Python3 (#73715) (#73723)
* [stable-2.10] Normalize ConfigParser between Python2 and Python3 (#73715)
* Normalize config parser between py2 and py3
* Add tests and changelog
* Use different config entry, since we supply certain env vars
(cherry picked from commit 950ab74)
* Update config entry
-rw-r--r-- | changelogs/fragments/73709-normalize-configparser.yml | 3 | ||||
-rw-r--r-- | lib/ansible/config/manager.py | 5 | ||||
-rw-r--r-- | test/integration/targets/config/inline_comment_ansible.cfg | 2 | ||||
-rwxr-xr-x | test/integration/targets/config/runme.sh | 3 |
4 files changed, 12 insertions, 1 deletions
diff --git a/changelogs/fragments/73709-normalize-configparser.yml b/changelogs/fragments/73709-normalize-configparser.yml new file mode 100644 index 0000000000..24b6d322d2 --- /dev/null +++ b/changelogs/fragments/73709-normalize-configparser.yml @@ -0,0 +1,3 @@ +bugfixes: +- ConfigManager - Normalize ConfigParser between Python2 and Python3 to for handling comments + (https://github.com/ansible/ansible/issues/73709) diff --git a/lib/ansible/config/manager.py b/lib/ansible/config/manager.py index 858dc4c645..99fc49fd1c 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -325,7 +325,10 @@ class ConfigManager(object): ftype = get_config_type(cfile) if cfile is not None: if ftype == 'ini': - self._parsers[cfile] = configparser.ConfigParser() + kwargs = {} + if PY3: + kwargs['inline_comment_prefixes'] = (';',) + self._parsers[cfile] = configparser.ConfigParser(**kwargs) with open(to_bytes(cfile), 'rb') as f: try: cfg_text = to_text(f.read(), errors='surrogate_or_strict') diff --git a/test/integration/targets/config/inline_comment_ansible.cfg b/test/integration/targets/config/inline_comment_ansible.cfg new file mode 100644 index 0000000000..afe9197dcc --- /dev/null +++ b/test/integration/targets/config/inline_comment_ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +cow_whitelist = ansibull ; BOOM diff --git a/test/integration/targets/config/runme.sh b/test/integration/targets/config/runme.sh index 73c3778b47..ea3989b88b 100755 --- a/test/integration/targets/config/runme.sh +++ b/test/integration/targets/config/runme.sh @@ -15,3 +15,6 @@ ANSIBLE_REMOTE_TMP="$HOME/.ansible/directory_with_no_space" ansible -m ping tes ANSIBLE_REMOTE_TMP="$HOME/.ansible/directory with space" ansible -m ping testhost -i ../../inventory "$@" ANSIBLE_CONFIG=nonexistent.cfg ansible-config dump --only-changed -v | grep 'No config file found; using defaults' + +# https://github.com/ansible/ansible/pull/73715 +ANSIBLE_CONFIG=inline_comment_ansible.cfg ansible-config dump --only-changed | grep "'ansibull'" |