ansible.builtin.zip filter – combine list elements
Note
This filter plugin is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
plugin name
zip
.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.zip
for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same filter plugin name.
Synopsis
Iterate over several iterables in parallel, producing tuples with an item from each one.
Input
This describes the input of the filter, the value before | ansible.builtin.zip
.
Parameter |
Comments |
---|---|
Original list. |
Positional parameters
This describes positional parameters of the filter. These are the values positional1
, positional2
and so on in the following
example: input | ansible.builtin.zip(positional1, positional2, ...)
Parameter |
Comments |
---|---|
Additional list(s). |
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 | ansible.builtin.zip(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
If Choices:
|
Notes
Note
When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters:
input | ansible.builtin.zip(positional1, positional2, key1=value1, key2=value2)
This is mostly a passhtrough to Python’s
zip
function.
Examples
# two => [[1, "a"], [2, "b"], [3, "c"], [4, "d"], [5, "e"], [6, "f"]]
two: "{{ [1,2,3,4,5,6] | zip(['a','b','c','d','e','f']) }}"
# three => [ [ 1, "a", "d" ], [ 2, "b", "e" ], [ 3, "c", "f" ] ]
three: "{{ [1,2,3] | zip(['a','b','c'], ['d','e','f']) }}"
# shorter => [[1, "a"], [2, "b"], [3, "c"]]
shorter: "{{ [1,2,3] | zip(['a','b','c','d','e','f']) }}"
# compose dict from lists of keys and values
mydcit: "{{ dict(keys_list | zip(values_list)) }}"
Return Value
Key |
Description |
---|---|
List of lists made of elements matching the positions of the input lists. Returned: success |
Hint
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.