diff --git a/changelogs/fragments/73709-normalize-configparser.yml b/changelogs/fragments/73709-normalize-configparser.yml new file mode 100644 index 00000000000000..24b6d322d25213 --- /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 858dc4c6451073..99fc49fd1c47a1 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -325,7 +325,10 @@ def _parse_config_file(self, cfile=None): 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 00000000000000..afe9197dcc5928 --- /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 73c3778b47adca..ea3989b88bca10 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'"