mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
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:
committed by
Brian Coca
parent
c4004b5fb1
commit
11279a909d
@@ -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'"
|
||||
|
||||
Reference in New Issue
Block a user