.. _ansible.utils.index_of_lookup: ********************** ansible.utils.index_of ********************** **Find the indicies of items in a list matching some criteria** Version added: 1.0 .. contents:: :local: :depth: 1 Synopsis -------- - This lookup returns the indicies 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 Parameters ---------- .. raw:: html
Parameter | Choices/Defaults | Configuration | Comments |
---|---|---|---|
data
list
/ 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 againt 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 expesion dict etc, depending on the test used |
||
wantlist
boolean
|
|
When only a single entry in the
data is matched, that entries index 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 accomplised 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 |