ansible.builtin.unique filter – set of unique items of a list

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 unique even without specifying the collections: keyword. However, we recommend you use the FQCN 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 1.4

Synopsis

  • Creates a list of unique elements (a set) from the provided input list.

Input

This describes the input of the filter, the value before | ansible.builtin.unique.

Parameter

Comments

Input

list / elements=string / required

A list.

See Also

See also

ansible.builtin.difference filter plugin

The official documentation on the ansible.builtin.difference filter plugin.

ansible.builtin.intersect filter plugin

The official documentation on the ansible.builtin.intersect filter plugin.

ansible.builtin.symmetric_difference filter plugin

The official documentation on the ansible.builtin.symmetric_difference filter plugin.

ansible.builtin.union filter plugin

The official documentation on the ansible.builtin.union filter plugin.

Examples

# return only the unique elements of list1
# list1: [1, 2, 5, 1, 3, 4, 10]
{{ list1 | unique }}
# => [1, 2, 5, 3, 4, 10]

Return Value

Key

Description

Return value

list / elements=string

A list with unique elements, also known as a set.

Returned: success

Authors

  • Brian Coca (@bcoca)

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.