fix vars hostname fallback
also made it optimistic, rely on exceptions instead of copmlex if chains
(cherry picked from commit 11dbed1350
)
This commit is contained in:
parent
1fe98e3066
commit
8fafecc979
2 changed files with 9 additions and 7 deletions
2
changelogs/fragments/vars_lk.yml
Normal file
2
changelogs/fragments/vars_lk.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- correctly check hostvars for vars term https://github.com/ansible/ansible/pull/41819
|
|
@ -78,15 +78,15 @@ class LookupModule(LookupBase):
|
|||
raise AnsibleError('Invalid setting identifier, "%s" is not a string, its a %s' % (term, type(term)))
|
||||
|
||||
try:
|
||||
if term in myvars:
|
||||
try:
|
||||
value = myvars[term]
|
||||
elif 'hostvars' in myvars and term in myvars['hostvars']:
|
||||
# maybe it is a host var?
|
||||
value = myvars['hostvars'][term]
|
||||
else:
|
||||
raise AnsibleUndefinedVariable('No variable found with this name: %s' % term)
|
||||
ret.append(self._templar.template(value, fail_on_undefined=True))
|
||||
except KeyError:
|
||||
try:
|
||||
value = myvars['hostvars'][myvars['inventory_hostname']][term]
|
||||
except KeyError:
|
||||
raise AnsibleUndefinedVariable('No variable found with this name: %s' % term)
|
||||
|
||||
ret.append(self._templar.template(value, fail_on_undefined=True))
|
||||
except AnsibleUndefinedVariable:
|
||||
if default is not None:
|
||||
ret.append(default)
|
||||
|
|
Loading…
Reference in a new issue