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

Signed-off-by: Yadnesh Kulkarni <ykulkarn@redhat.com>
This commit is contained in:
Yadnesh Kulkarni 2020-11-20 23:52:55 +05:30 committed by GitHub
parent 18e5628b19
commit 3add96909d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 1 deletions

View file

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

View file

@ -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__'):

View file

@ -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

View file

@ -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"}