fix combine filter using undefined vars (#55840)

* Check variables are defined before using combine filter

* Add tests for the combine filter

* Remove dependencies that should already be installed

* relocate the function to recursively check for undefined vars

add another test

* changelog
This commit is contained in:
Sloane Hertel
2019-04-30 11:10:20 -04:00
committed by Brian Coca
parent c4004b5fb1
commit 11279a909d
4 changed files with 53 additions and 0 deletions

View File

@@ -277,3 +277,37 @@
loop: "{{ hostvars|dict2items }}"
loop_control:
label: "{{ item.key }}"
- name: Ensure combining two dictionaries containing undefined variables provides a helpful error
block:
- set_fact:
foo:
key1: value1
- set_fact:
combined: "{{ foo | combine({'key2': undef_variable}) }}"
ignore_errors: yes
register: result
- assert:
that:
- "result.msg.startswith('The task includes an option with an undefined variable')"
- set_fact:
combined: "{{ foo | combine({'key2': {'nested': [undef_variable]}})}}"
ignore_errors: yes
register: result
- assert:
that:
- "result.msg.startswith('The task includes an option with an undefined variable')"
- set_fact:
key2: is_defined
- set_fact:
combined: "{{ foo | combine({'key2': key2}) }}"
- assert:
that:
- "combined.key2 == 'is_defined'"