template/__init__.py - fix KeyError when wantlist=False with non-list

pull/77826/head
Joseph Torcasso 3 years ago committed by GitHub
parent 5e50284693
commit c9ce7d08a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- lookup plugin - catch KeyError when lookup returns dictionary (https://github.com/ansible/ansible/pull/77789).

@ -1014,6 +1014,11 @@ class Templar:
else:
ran = wrap_var(ran)
except KeyError:
# Lookup Plugin returned a dict. Return comma-separated string.
# See https://github.com/ansible/ansible/pull/77789
ran = wrap_var(",".join(ran))
return ran
def _make_undefined(self, hint=None):

@ -2,7 +2,7 @@
set -eux
ANSIBLE_ROLES_PATH=./ UNICODE_VAR=café ansible-playbook runme.yml "$@"
ANSIBLE_LOOKUP_PLUGINS=. ANSIBLE_ROLES_PATH=./ UNICODE_VAR=café ansible-playbook runme.yml "$@"
ansible-playbook template_lookup_vaulted/playbook.yml --vault-password-file template_lookup_vaulted/test_vault_pass "$@"

@ -0,0 +1,6 @@
from ansible.plugins.lookup import LookupBase
class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
return {'one': 1, 'two': 2}

@ -87,4 +87,15 @@
that:
- password1 != password2
# 77788 - KeyError when wantlist=False with dict returned
- name: Test that dicts can be parsed with wantlist false
set_fact:
dict_wantlist_true: "{{ lookup('77788', wantlist=True) }}"
dict_wantlist_false: "{{ lookup('77788', wantlist=False) }}"
- assert:
that:
- dict_wantlist_true is mapping
- dict_wantlist_false is string
- include_tasks: ./errors.yml

Loading…
Cancel
Save