ansible.builtin.indexed_items lookup – rewrites lists to return ‘indexed items’
Note
This lookup plugin is part of ansible-core
and included in all Ansible installations. In most cases, you can use the short plugin name indexed_items
. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.indexed_items
for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same lookup plugin name.
Synopsis
- use this lookup if you want to loop over an array and also get the numeric index of where you are in the array as you go
- any list given will be transformed with each resulting element having the it’s previous position in item.0 and its value in item.1
Terms
Parameter | Comments |
---|---|
Terms string / required | list of items |
Examples
- name: indexed loop demo ansible.builtin.debug: msg: "at array position {{ item.0 }} there is a value {{ item.1 }}" with_indexed_items: - "{{ some_list }}"
Return Value
Key | Description |
---|---|
Return value list / elements=list | list with each item.0 giving you the position and item.1 the value Returned: success |
Collection links
© 2012–2018 Michael DeHaan
© 2018–2024 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/indexed_items_lookup.html