Fix parsing of values when using an empty string as key (#57132) (#72545)

Signed-off-by: Yadnesh Kulkarni <ykulkarn@redhat.com>
pull/72705/head
Yadnesh Kulkarni 4 years ago committed by GitHub
parent 18e5628b19
commit 3add96909d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Fix parsing of values when using empty string as a key (https://github.com/ansible/ansible/issues/57132)

@ -797,7 +797,7 @@ class Templar:
set to True, the given data will be wrapped as a jinja2 variable ('{{foo}}')
before being sent through the template engine.
'''
static_vars = [''] if static_vars is None else static_vars
static_vars = [] if static_vars is None else static_vars
# Don't template unsafe variables, just return them.
if hasattr(variable, '__UNSAFE__'):

@ -28,3 +28,6 @@ ansible-playbook -i inventory --flush-cache "$@" set_fact_no_cache.yml
# Test boolean conversions in set_fact
ANSIBLE_JINJA2_NATIVE=0 ansible-playbook -v set_fact_bool_conv.yml
ANSIBLE_JINJA2_NATIVE=1 ansible-playbook -v set_fact_bool_conv_jinja2_native.yml
# Test parsing of values when using an empty string as a key
ansible-playbook -i inventory set_fact_empty_str_key.yml

@ -0,0 +1,15 @@
- name: Test set_fact for empty string as a key
hosts: testhost
gather_facts: no
vars:
value: 1
tasks:
- name: Define fact with key as an empty string
set_fact:
foo:
"": "bar{{ value }}"
- name: Verify the parsed value of the key
assert:
that:
- foo == {"":"bar1"}
Loading…
Cancel
Save