community.general.merge_variables lookup – merge variables with a certain suffix
Note
This lookup plugin is part of the community.general collection (version 6.6.2).
You might already have this collection installed if you are using the ansible
package.
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 community.general
.
To use it in a playbook, specify: community.general.merge_variables
.
New in community.general 6.5.0
Synopsis
This lookup returns the merged result of all variables in scope that match the given prefixes, suffixes, or regular expressions, optionally.
Terms
Parameter |
Comments |
---|---|
Depending on the value of pattern_type, this is a list of prefixes, suffixes, or regular expressions that will be used to match all variables that should be merged. |
Parameters
Parameter |
Comments |
---|---|
An initial value to start with. |
|
Return an error, print a warning or ignore it when a key will be overwritten. The default behavior When Choices:
Configuration:
|
|
Change the way of searching for the specified pattern. Choices:
Configuration:
|
Examples
# Some example variables, they can be defined anywhere as long as they are in scope
test_init_list:
- "list init item 1"
- "list init item 2"
testa__test_list:
- "test a item 1"
testb__test_list:
- "test b item 1"
testa__test_dict:
ports:
- 1
testb__test_dict:
ports:
- 3
# Merge variables that end with '__test_dict' and store the result in a variable 'example_a'
example_a: "{{ lookup('community.general.merge_variables', '__test_dict', pattern_type='suffix') }}"
# The variable example_a now contains:
# ports:
# - 1
# - 3
# Merge variables that match the '^.+__test_list$' regular expression, starting with an initial value and store the
# result in a variable 'example_b'
example_b: "{{ lookup('community.general.merge_variables', '^.+__test_list$', initial_value=test_init_list) }}"
# The variable example_b now contains:
# - "list init item 1"
# - "list init item 2"
# - "test a item 1"
# - "test b item 1"
Return Value
Key |
Description |
---|---|
In case the search matches list items, a list will be returned. In case the search matches dicts, a dict will be returned. Returned: success |
Collection links
Issue Tracker Repository (Sources) Submit a bug report Request a feature Communication