mirror of https://github.com/ansible/ansible.git
[stable-2.11] ini lookup - catch and handle duplicate key and missing section errors (#74629) (#74682)
* Remove unused import
* Add integration tests for errors
* Cleanup formatting on existing tests
* Add changelog.
(cherry picked from commit 0affe4d027
)
* Add note about Py2/3 differences regarding key names
* Fix tests
Kwarg parsing wasn't backported.
pull/74728/head
parent
a624731700
commit
cf8df3faa4
@ -0,0 +1,2 @@
|
||||
bugfixes:
|
||||
- ini lookup - handle errors for duplicate keys and missing sections (https://github.com/ansible/ansible/issues/74601)
|
@ -0,0 +1,3 @@
|
||||
[reggae]
|
||||
name = bob
|
||||
name = marley
|
@ -0,0 +1,3 @@
|
||||
[reggae]
|
||||
name = bob
|
||||
NAME = marley
|
@ -0,0 +1,2 @@
|
||||
[all]
|
||||
testhost ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}"
|
@ -0,0 +1,38 @@
|
||||
- name: Test INI lookup errors
|
||||
hosts: testhost
|
||||
|
||||
tasks:
|
||||
- name: Test for failure on Python 3
|
||||
when: ansible_facts.python.version_info[0] >= 3
|
||||
block:
|
||||
- name: Lookup a file with duplicate keys
|
||||
debug:
|
||||
msg: "{{ lookup('ini', 'reggae file=duplicate.ini section=reggae') }}"
|
||||
ignore_errors: yes
|
||||
register: duplicate
|
||||
|
||||
- name: Lookup a file with keys that differ only in case
|
||||
debug:
|
||||
msg: "{{ lookup('ini', 'reggae file=duplicate_case_check.ini section=reggae') }}"
|
||||
ignore_errors: yes
|
||||
register: duplicate_case_sensitive
|
||||
|
||||
- name: Ensure duplicate key errers were handled properly
|
||||
assert:
|
||||
that:
|
||||
- duplicate is failed
|
||||
- "'Duplicate option in' in duplicate.msg"
|
||||
- duplicate_case_sensitive is failed
|
||||
- "'Duplicate option in' in duplicate_case_sensitive.msg"
|
||||
|
||||
- name: Lookup a file with a missing section
|
||||
debug:
|
||||
msg: "{{ lookup('ini', 'reggae file=lookup.ini section=missing') }}"
|
||||
ignore_errors: yes
|
||||
register: missing_section
|
||||
|
||||
- name: Ensure error was shown for a missing section
|
||||
assert:
|
||||
that:
|
||||
- missing_section is failed
|
||||
- "'No section' in missing_section.msg"
|
Loading…
Reference in New Issue