With_index_items returns a two item list. The first value items[0] is the index, the value items[1] is the name of the host, which is what you actually do see in the output above.
Switching to "with_items" will resolve this with no changes, otherwise in the dereference of hostvars change items to items[1] On Fri, Mar 21, 2014 at 1:55 PM, James Tanner <[email protected]> wrote: > Before the mysql_user task, add a debug task to check the hostvars data > structure ... > > - debug: var=hostvars > > That should tell you what is available during the play execution. > > On Mar 21, 2014, at 10:53 AM, David Neudorfer < > [email protected]> wrote: > > Ansible is telling me that the HostVars object has no element, but when I > run setup I see the object! > > setup: > > "ansible_eth1": { > "active": true, > "device": "eth1", > "ipv4": { > "address": "10.209.169.109", > "netmask": "255.255.224.0", > "network": "10.209.160.0" > > > playbook run: > > TASK: [hibbert_db | Create a new database user for hibbert_backend.* with > name hibbert_user and all privileges from local] *** > <10.209.169.109> ESTABLISH CONNECTION FOR USER: mozart on PORT 22 TO > 10.209.169.109 > fatal: [s-mysql01] => One or more undefined variables: > ansible.runner.HostVars object has no element [0, 's-mysql01'] > > the task: > > - name: Create a new database user for {{ db_name }}.* with name {{ > db_user }} and all privileges from local > tags: > - user > - permissions > mysql_user: host={{ hostvars[item]['ansible_eth1']['ipv4']['address'] }} > name={{ db_user }} password={{ db_password }} priv={{ db_root_name }}.*:ALL > state=present > with_indexed_items: groups['hibbert_db'] > sudo: yes > > Does anyone have any ideas? Google has been no help. > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/6cd2d2fb-fecb-4c2a-8048-64fc054a15b7%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/6cd2d2fb-fecb-4c2a-8048-64fc054a15b7%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/DCFDD966-61FF-4156-912E-8FF4970DB44F%40gmail.com<https://groups.google.com/d/msgid/ansible-project/DCFDD966-61FF-4156-912E-8FF4970DB44F%40gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEVJ8QOw31mi_TvyHLPdidp8yV4brt%2BT009tPnomPqBEngyKHQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
