flatten¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.5.
Synopsis¶
- For a given list, take any elements that are lists and insert their elements into the parent list directly.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _input dict required |
First dictionary to combine. | |
| levels int |
Number of recursive list depths to flatten. | |
| skip_nulls bool |
Default: True |
Skip V(null)/V(None) elements when inserting into the top list. |
Examples¶
# [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) }}"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | list | The flattened list. |