ansible.builtin.subelements filter – returns a product of a list and its 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
subelements
.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.subelements
for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same filter plugin name.
New in Ansible 2.7
Synopsis
This produces a product of an object and the subelement values of that object, similar to the subelements lookup. This lets you specify individual subelements to use in a template
_input
.
Input
This describes the input of the filter, the value before | ansible.builtin.subelements
.
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.subelements(positional1, positional2, ...)
Parameter |
Comments |
---|---|
Label of property to extract from original list items. |
|
If Choices:
|
Examples
# data
users:
- groups: [1,2,3]
name: lola
- name: fernando
groups: [2,3,4]
# user_w_groups =>[ { "groups": [ 1, 2, 3 ], "name": "lola" }, 1 ], [ { "groups": [ 1, 2, 3 ], "name": "lola" }, 2 ], [ { "groups": [ 1, 2, 3 ], "name": "lola" }, 3 ], [ { "groups": [ 2, 3, 4 ], "name": "fernando" }, 2 ], [ { "groups": [ 2, 3, 4 ], "name": "fernando" }, 3 ], [ { "groups": [ 2, 3, 4 ], "name": "fernando" }, 4 ] ]
users_w_groups: {{ users | subelements('groups', skip_missing=True) }}
Return Value
Key |
Description |
---|---|
List made of original list and product of the subelement list. 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.