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 flatten. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.flatten for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.
This describes the input of the filter, the value before | ansible.builtin.flatten.
Parameter | Comments |
|---|---|
Input dictionary / required | First dictionary to combine. |
This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | ansible.builtin.flatten(positional1, positional2, ...)
Parameter | Comments |
|---|---|
levels integer | Number of recursive list depths to flatten. |
skip_nulls boolean | Skip Choices:
|
# [1,2,3,4,5,6]
flat: "{{ [1 , 2, [3, [4, 5]], 6] | flatten }}"
# [1,2,3,[4,5],6]
flatone: "{{ [1, 2, [3, [4, 5]], 6] | flatten(1) }}"
Key | Description |
|---|---|
Return value list / elements=string | The flattened list. Returned: success |
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/flatten_filter.html