|
Server : LiteSpeed System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64 User : elvh3918 ( 1528) PHP Version : 8.2.31 Disable Function : mail Directory : /proc/self/root/usr/lib/python3.9/site-packages/ansible/plugins/filter/ |
DOCUMENTATION:
name: extract
version_added: "2.1"
short_description: extract a value based on an index or key
description:
- Extract a value from a list or dictionary based on an index/key.
- User must ensure that index or key used matches the type of container.
- Equivalent of using C(list[index]) and C(dictionary[key]) but useful as a filter to combine with C(map).
positional: _input, container, morekeys
options:
_input:
description: Index or key to extract.
type: raw
required: true
contianer:
description: Dictionary or list from which to extract a value.
type: raw
required: true
morekeys:
description: Indicies or keys to extract from the initial result (subkeys/subindices).
type: list
elements: dictionary
required: true
EXAMPLES: |
# extracted => 'b', same as ['a', 'b', 'c'][1]
extracted: "{{ 1 | extract(['a', 'b', 'c']) }}"
# extracted_key => '2', same as {'a': 1, 'b': 2, 'c': 3}['b']
extracted_key: "{{ 'b' | extract({'a': 1, 'b': 2, 'c': 3}) }}"
# extracted_key_r => '2', same as [{'a': 1, 'b': 2, 'c': 3}, {'x': 9, 'y': 10}][0]['b']
extracted_key_r: "{{ 0 | extract([{'a': 1, 'b': 2, 'c': 3}, {'x': 9, 'y': 10}], morekeys='b') }}"
RETURN:
_value:
description: Resulting merge of supplied dictionaries.
type: dict