Looping over subelements

Hello,

I’m unable to get the “looping over subelements” example on this page:
http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-subelements

to work. Specifically, when I copy-and-paste “users” into my file “group_vars/test” and attempt to run:

  • debug:
    msg:
  • “{{ item.0.name }}”
  • “{{ item.0.mysql.password }}”
  • “{{ item.1 }}”
  • “{{ item.0.mysql.privs | join(‘/’) }}”
    with_subelements:
  • “{{ users }}”
  • “{{ mysql.hosts }}”

ansible-playbook reports:

[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error.: ‘mysql’ is undefined.
This feature will be removed in a future
release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File “/opt/Python-2.7.6/lib/python2.7/site-packages/ansible/executor/task_executor.py”, line 91, in run
items = self._get_loop_items()
File “/opt/Python-2.7.6/lib/python2.7/site-packages/ansible/executor/task_executor.py”, line 191, in _get_loop_items
items = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader, templar=templar).run(terms=loop_terms, variables=self._job_vars, wantlist=True)
File “/opt/Python-2.7.6/lib/python2.7/site-packages/ansible/plugins/lookup/subelements.py”, line 37, in run
terms[0] = listify_lookup_plugin_terms(terms[0], templar=self._templar, loader=self._loader)
IndexError: list index out of range

fatal: [imdb410a.unx.sas.com]: FAILED! => {“failed”: true, “msg”: “Unexpected failure during module execution.”, “stdout”: “”}

I don’t want to set up any mysql users. I want an example to work with because I want to use a similar data structure in our playbooks.

The group “all” is implicit for every host in the inventory file, which is why the example works. You chose to define the users in the group_var “test”, therefore your host needs to belong to also belong to that group. Add the host you’re running this playbook against to a group called test in your inventory file and it should work:

[test]
localhost
host1

Am I wrong to think this should have been asked in Ansible Project and not Ansible Development?

The host I’m running this playbook against is in a group called “test” in my inventory file:

[test]
server.example.com ansible_connection=ssh

To answer your question, I followed the link to the “User Mailing List” at the bottom of this page:
http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-subelements

which states: “Have a question? Stop by the google group!” Perhaps that should link to group “Ansible Project” (if that’s the desired intent), or it should be named “Developer Mailing List” to make it clear it’s intended for ansible developers, not users.

I’ll follow up on ansible-project. Thanks.