# alternatives module loop

**URL:** <https://forum.ansible.com/t/alternatives-module-loop/27863>\
**Category:** Ansible Project\
**Created:** [June 25, 2018, 2:20pm UTC](https://forum.ansible.com/t/alternatives-module-loop/27863 "2018-06-25T14:20:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alix\_Ak](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@Alix\_Ak](https://forum.ansible.com/u/Alix_Ak)\
**Post date:** [June 25, 2018, 2:20pm UTC](https://forum.ansible.com/t/alternatives-module-loop/27863/1 "2018-06-25T14:20:57Z")

</div>

- name: Install java alternatives  
alternatives:  
name: “{{ item.name }}”  
link: “{{ item.link }}”  
path: “{{ item.path }}”  
with\_items:
- { name: ‘java’, link: ‘/usr/bin/java’, path: ‘/usr/share/java-1.8.0/jre1.8.0\_172/bin/java’ }
- { name: ‘javaws’, link: ‘/usr/bin/javaws’, path: ‘/usr/share/java-1.8.0/jre1.8.0\_172/bin/javaws’ }

when i insert the values as a key for exmpl. path: ‘/usr/share/java-1.8.0/jre1.8.0\_172/bin/javaws’ the task executes without any problem but when looping over i get “msg”: "The task includes an option with an undefined variable.i am suspecting that the value of the path is being parsed as an array [’  
/usr/share/java-1.8.0/jre1.8.0\_172/bin/javaws’]. Does anybody know what going wrong here and how can i get the loop working?

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [June 25, 2018, 3:10pm UTC](https://forum.ansible.com/t/alternatives-module-loop/27863/2 "2018-06-25T15:10:57Z")

</div>

Which variable does the message say is undefined?

If the path element had been parsed as a list, I don’t think you would get an error about an undefined variable.

---

<div class="post-metadata">

**Author:** ![Alix\_Ak](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@Alix\_Ak](https://forum.ansible.com/u/Alix_Ak)\
**Post date:** [June 26, 2018, 9:34am UTC](https://forum.ansible.com/t/alternatives-module-loop/27863/3 "2018-06-26T09:34:40Z")

</div>

the error message is not mentioning which variable is undefined. I shifted the lists as you mentioned above but i am still getting the same error. Here is the complete error message:

The task includes an option with an undefined variable. The error was: ‘item’ is undefined

The error appears to have been in ‘/Ansible/roles/oracle-java-8/tasks/main.yaml’: line 39, column 3, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Install java alternatives  
^ here

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 26, 2018, 3:03pm UTC](https://forum.ansible.com/t/alternatives-module-loop/27863/4 "2018-06-26T15:03:41Z")

</div>

'item' is undefined because you don't have a loop, you've indented  
with\_items too much, it is a TASK keyword, not a MODULE option.
