sap.sap_operations.combine_default filter – Combine two dictionaries, second dictionary will be used as default.
Note
This filter plugin is part of the sap.sap_operations collection.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install sap.sap_operations
.
To use it in a playbook, specify: sap.sap_operations.combine_default
.
New in sap.sap_operations 1.11.0
Synopsis
Combine two dictionaries, second dictionary will be used as default.
If key is present in both dictionaries, value from first dictionary (not value from default) will be used.
If value is not dictionary, it will be returned as is.
If value is None, default will be returned.
This is expected to work only with one level of nesting for dictionaries.
Keyword parameters
This describes keyword parameters of the filter. These are the values key1=value1
, key2=value2
and so on in the following
example: input | sap.sap_operations.combine_default(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
Dictionary to use as default. |
|
Dictionary to combine with default. |
Examples
- name: Test filter `combine_default`, this assertion is True
ansible.builtin.assert:
that:
- ( 'ABC' | sap.sap_operations.combine_default('DEF') ) == 'ABC'
- ( 123 | sap.sap_operations.combine_default('DEF') ) == 123
- ( [1, 2, 3] | sap.sap_operations.combine_default('DEF') ) == [1, 2, 3]
- ( {"key":"value"} | sap.sap_operations.combine_default('DEF') ) == {"key":"value"}
- True | sap.sap_operations.combine_default('DEF') == True
- False | sap.sap_operations.combine_default('DEF') == False
- 0 | sap.sap_operations.combine_default('DEF') == 0
- 1 | sap.sap_operations.combine_default('DEF') == 1
- None | sap.sap_operations.combine_default('DEF') == 'DEF'
- value | sap.sap_operations.combine_default(default) == result1
- default | sap.sap_operations.combine_default(value) == result2
vars:
value:
key1: value1
key2: value2
default:
key2: new_value2
key3: value3
result1:
key1: value1
key2: value2
key3: value3
result2:
key1: value1
key2: new_value2
key3: value3
Return Value
Key |
Description |
---|---|
Combined dictionary. If key is present in both dictionaries, value from first dictionary (not value from default) will be used. If value is not dictionary, it will be returned as is. If value is None, default will be returned. Returned: success |