This commit is contained in:
Abhijeet Kasurde 2026-05-27 22:06:47 -05:00 committed by GitHub
commit ece5d4a2e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 7 deletions

View file

@ -74,7 +74,7 @@ class AnsibleInstrumentedConstructor(_BaseConstructor):
if self._duplicate_key_mode == 'error':
raise AnsibleConstructorError(problem=msg, problem_mark=key_node.start_mark)
if self._duplicate_key_mode == 'warn':
if self._duplicate_key_mode in ['warn', 'warning']:
display.warning(msg=msg, obj=key, help_text='Using last defined value only.')
keys.add(key)

View file

@ -1368,10 +1368,9 @@ DUPLICATE_YAML_DICT_KEY:
ini:
- {key: duplicate_dict_key, section: defaults}
type: string
choices: &basic_error2
error: issue a 'fatal' error and stop the play
choices:
<<: *basic_error
warn: issue a warning but continue
ignore: just continue silently
version_added: "2.9"
ERROR_ON_MISSING_HANDLER:
name: Missing handler error
@ -2086,7 +2085,7 @@ _TEMPLAR_UNTRUSTED_TEMPLATE_BEHAVIOR:
default: ignore
description:
- Action to take when processing of an untrusted template is skipped.
- For `ignore` or `warn`, the input template string is returned as-is.
- For `ignore` or `warning`, the input template string is returned as-is.
- This setting has no effect on expressions.
- Experimental diagnostic feature, subject to change.
type: choices

View file

@ -4,10 +4,18 @@
ANSIBLE_DUPLICATE_YAML_DICT_KEY: warn
register: duplicate_warn
- name: Test ANSIBLE_DUPLICATE_YAML_DICT_KEY=warning
command: ansible-playbook {{ verbosity }} {{ role_path }}/playbook.yml
environment:
ANSIBLE_DUPLICATE_YAML_DICT_KEY: warning
register: duplicate_warning
- assert:
that:
- duplicate_warn.stderr is contains("Found duplicate mapping key 'foo'")
- duplicate_warn.rc == 0
- duplicate_warning.stderr is contains("Found duplicate mapping key 'foo'")
- duplicate_warning.rc == 0
- name: Test ANSIBLE_DUPLICATE_YAML_DICT_KEY=error
command: ansible-playbook {{ verbosity }} {{ role_path }}/playbook.yml

View file

@ -98,8 +98,9 @@ def test_yaml_parser_error(
assert error.value._help_text is None
def test_yaml_duplicate_key_warning(mocker: pytest_mock.MockerFixture) -> None:
set_duplicate_yaml_dict_key_config(mocker, 'warn')
@pytest.mark.parametrize("mode", ['warn', 'warning'])
def test_yaml_duplicate_key_warning(mocker: pytest_mock.MockerFixture, mode: str) -> None:
set_duplicate_yaml_dict_key_config(mocker, mode)
patched_warning = mocker.patch.object(Display(), 'warning')