# ansible.runner.HostVars object has no element

**URL:** <https://forum.ansible.com/t/ansible-runner-hostvars-object-has-no-element/14821>\
**Category:** Ansible Project\
**Created:** [March 21, 2014, 2:53pm UTC](https://forum.ansible.com/t/ansible-runner-hostvars-object-has-no-element/14821 "2014-03-21T14:53:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.neudorfer](https://avatars.discourse-cdn.com/v4/letter/d/b38774/32.png) [@david.neudorfer](https://forum.ansible.com/u/david.neudorfer)\
**Post date:** [March 21, 2014, 2:53pm UTC](https://forum.ansible.com/t/ansible-runner-hostvars-object-has-no-element/14821/1 "2014-03-21T14:53:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [March 21, 2014, 5:55pm UTC](https://forum.ansible.com/t/ansible-runner-hostvars-object-has-no-element/14821/2 "2014-03-21T17:55:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 21, 2014, 8:18pm UTC](https://forum.ansible.com/t/ansible-runner-hostvars-object-has-no-element/14821/3 "2014-03-21T20:18:15Z")

</div>

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]
