.. _ansible.utils.index_of_lookup: ********************** ansible.utils.index_of ********************** **Find the indices of items in a list matching some criteria** Version added: 1.0.0 .. contents:: :local: :depth: 1 Synopsis -------- - This plugin returns the indices of items matching some criteria in a list. - When working with a list of dictionaries, the key to evaluate can be specified. - **index_of** is also available as a **filter plugin** for convenience. - Using the parameters below- ``lookup('ansible.utils.index_of', data, test, value, key, fail_on_missing, wantlist``). Parameters ---------- .. raw:: html
Parameter | Choices/Defaults | Configuration | Comments |
---|---|---|---|
data
list
/ elements=raw
/ required
|
A list of items to enumerate and test against.
|
||
fail_on_missing
boolean
|
|
When provided a list of dictionaries, fail if the key is missing from one or more of the dictionaries.
|
|
key
string
|
When the data provided is a list of dictionaries, run the test against this dictionary key. When using a key, the data must only contain dictionaries. See fail_on_missing below to determine the behaviour when the key is missing from a dictionary in the data.
|
||
test
string
/ required
|
The name of the test to run against the list, a valid jinja2 test or ansible test plugin. Jinja2 includes the following tests http://jinja.palletsprojects.com/templates/#builtin-tests. An overview of tests included in ansible https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html.
|
||
value
raw
|
The value used to test each list item against. Not required for simple tests (eg:
true , false , even , odd ) May be a string , boolean , number , regular expression dict and so on, depending on the test used. |
||
wantlist
boolean
|
|
When only a single entry in the data is matched, the index of that entry is returned as an integer. If set to
True , the return value will always be a list, even if only a single entry is matched. This can also be accomplished using query or q instead of lookup . https://docs.ansible.com/ansible/latest/plugins/lookup.html |
Key | Returned | Description |
---|---|---|
_raw
-
|
One or more zero-based indicies of the matching list items.
See
wantlist if a list is always required. |