alternatives module loop

  • 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?

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.

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

'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.