community.general.flattened lookup – return single list completely flattened

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.flattened.

Synopsis

  • Given one or more lists, this lookup will flatten any list elements found recursively until only 1 list is left.

Terms

Parameter

Comments

Terms

list / elements=any / required

lists to flatten

Notes

Note

  • Unlike the items lookup which only flattens 1 level, this plugin will continue to flatten until it cannot find lists anymore.

  • Aka highlander plugin, there can only be one (list).

Examples

- name: "'unnest' all elements into single list"
  ansible.builtin.debug:
    msg: "all in one list {{lookup('community.general.flattened', [1,2,3,[5,6]], ['a','b','c'], [[5,6,1,3], [34,'a','b','c']])}}"

Return Value

Key

Description

Return value

list / elements=string

flattened list

Returned: success

Authors

  • Serge van Ginderachter

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.