Ini fixes (#74285)
* avoid 'mixed' param formats * added tests * clog * fixed alignment
This commit is contained in:
parent
8e5dc7306e
commit
c6945de899
3 changed files with 22 additions and 1 deletions
2
changelogs/fragments/ini_lookup_baduser.yml
Normal file
2
changelogs/fragments/ini_lookup_baduser.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- ini lookup - better error on mixed/bad parameters
|
|
@ -65,7 +65,7 @@ import re
|
|||
from io import StringIO
|
||||
from collections import defaultdict
|
||||
|
||||
from ansible.errors import AnsibleLookupError
|
||||
from ansible.errors import AnsibleLookupError, AnsibleOptionsError
|
||||
from ansible.module_utils.six.moves import configparser
|
||||
from ansible.module_utils._text import to_bytes, to_text, to_native
|
||||
from ansible.module_utils.common._collections_compat import MutableSequence
|
||||
|
@ -132,6 +132,7 @@ class LookupModule(LookupBase):
|
|||
self._deprecate_inline_kv()
|
||||
params = _parse_params(term, paramvals)
|
||||
try:
|
||||
updated_key = False
|
||||
for param in params:
|
||||
if '=' in param:
|
||||
name, value = param.split('=')
|
||||
|
@ -141,9 +142,13 @@ class LookupModule(LookupBase):
|
|||
elif key == term:
|
||||
# only take first, this format never supported multiple keys inline
|
||||
key = param
|
||||
updated_key = True
|
||||
except ValueError as e:
|
||||
# bad params passed
|
||||
raise AnsibleLookupError("Could not use '%s' from '%s': %s" % (param, params, to_native(e)), orig_exc=e)
|
||||
if not updated_key:
|
||||
raise AnsibleOptionsError("No key to lookup was provided as first term with in string inline options: %s" % term)
|
||||
# only passed options in inline string
|
||||
|
||||
# TODO: look to use cache to avoid redoing this for every term if they use same file
|
||||
# Retrieve file path
|
||||
|
|
|
@ -69,3 +69,17 @@
|
|||
that:
|
||||
- '_.results.0.item == "section1/value1"'
|
||||
- '_.results.1.item == "section1/value2"'
|
||||
|
||||
|
||||
- name: capture bad behaviour
|
||||
block:
|
||||
- name: mix options type and push key out of order
|
||||
debug: msg="{{ lookup('ini', 'file=lookup.ini', 'value1', section='value_section') }}"
|
||||
register: bad_mojo
|
||||
ignore_errors: true
|
||||
|
||||
- name: verify
|
||||
assert:
|
||||
that:
|
||||
- bad_mojo is failed
|
||||
- '"No key to lookup was provided as first term with in string inline option" in bad_mojo.msg'
|
||||
|
|
Loading…
Reference in a new issue