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:
parent
eb72c36a71
commit
950ab74758
4 changed files with 12 additions and 1 deletions
3
changelogs/fragments/73709-normalize-configparser.yml
Normal file
3
changelogs/fragments/73709-normalize-configparser.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
bugfixes:
|
||||
- ConfigManager - Normalize ConfigParser between Python2 and Python3 to for handling comments
|
||||
(https://github.com/ansible/ansible/issues/73709)
|
|
@ -329,7 +329,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')
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
[defaults]
|
||||
cowsay_enabled_stencils = ansibull ; BOOM
|
|
@ -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'"
|
||||
|
|
Loading…
Reference in a new issue