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
This commit is contained in:
Matt Martz 2021-02-25 11:03:03 -06:00 committed by GitHub
parent eb72c36a71
commit 950ab74758
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 1 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- ConfigManager - Normalize ConfigParser between Python2 and Python3 to for handling comments
(https://github.com/ansible/ansible/issues/73709)

View file

@ -329,7 +329,10 @@ class ConfigManager(object):
ftype = get_config_type(cfile) ftype = get_config_type(cfile)
if cfile is not None: if cfile is not None:
if ftype == 'ini': 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: with open(to_bytes(cfile), 'rb') as f:
try: try:
cfg_text = to_text(f.read(), errors='surrogate_or_strict') cfg_text = to_text(f.read(), errors='surrogate_or_strict')

View file

@ -0,0 +1,2 @@
[defaults]
cowsay_enabled_stencils = ansibull ; BOOM

View file

@ -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_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' 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'"