mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
When value does not exist, return default value instead of stopping ansible with an exception.
This commit is contained in:
parent
c2968d6d84
commit
733d40a77c
2 changed files with 6 additions and 3 deletions
|
@ -43,9 +43,11 @@ class LookupModule(object):
|
||||||
# Retrieve all values from a section using a regexp
|
# Retrieve all values from a section using a regexp
|
||||||
if is_regexp:
|
if is_regexp:
|
||||||
return [v for k, v in self.cp.items(section) if re.match(key, k)]
|
return [v for k, v in self.cp.items(section) if re.match(key, k)]
|
||||||
|
value = None
|
||||||
# Retrieve a single value
|
# Retrieve a single value
|
||||||
|
try:
|
||||||
value = self.cp.get(section, key)
|
value = self.cp.get(section, key)
|
||||||
if value == None:
|
except ConfigParser.NoOptionError, e:
|
||||||
return dflt
|
return dflt
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
|
@ -26,4 +26,5 @@
|
||||||
with_items: [ 'value_section', 'other_section' ]
|
with_items: [ 'value_section', 'other_section' ]
|
||||||
- name: "Reading unknown value"
|
- name: "Reading unknown value"
|
||||||
set_fact:
|
set_fact:
|
||||||
value2_section2: "{{lookup('ini', 'value2 section=section1 file=lookup.ini')}}"
|
unknown: "{{lookup('ini', 'value2 default=unknown section=section1 file=lookup.ini')}}"
|
||||||
|
- debug: var=unknown
|
||||||
|
|
Loading…
Reference in a new issue