# Pass dictionary variables to the role does not work

**URL:** <https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181>\
**Category:** Ansible Project\
**Created:** [January 5, 2015, 3:55am UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181 "2015-01-05T03:55:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [January 5, 2015, 3:55am UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181/1 "2015-01-05T03:55:43Z")

</div>

Hi,

I cannot install ansible to one of our NFS server, I tried to fake a dictionary variable at following playbook:

- { role: nfs-client, nfsServer: { ‘ansible\_facts’: { ‘ansible\_eth0’ : { ‘ipv4’ : { ‘address’: ‘[hce.com](http://hce.com)’ } } } } }

The nfs-client tasks uses the variable nfsServer[‘ansible\_facts’], but I got following error, it cannot find dictionary variable nfsServer[‘ansible\_facts’]:

fatal: One or more undefined variables: ‘dict’ object has no attribute ‘ansible\_facts’.

What I was missing the syntax here?

Thanks.

- j

---

<div class="post-metadata">

**Author:** ![Tom\_Bamford](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Tom\_Bamford](https://forum.ansible.com/u/Tom_Bamford)\
**Post date:** [January 5, 2015, 4:15am UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181/2 "2015-01-05T04:15:14Z")

</div>

What version of Ansible are you using? It works for me with v1.8.2. Even when referencing an undefined variable, I don’t get an exception.

Can you paste the nfs-client task which fails?

Tom

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [January 5, 2015, 7:59am UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181/3 "2015-01-05T07:59:25Z")

</div>

ve1.7, I am going to update to v1.8.2 and will see how it goes.

Thanks Tom.

- j

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [January 5, 2015, 11:28pm UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181/4 "2015-01-05T23:28:37Z")

</div>

After updating to v1.8.2, I’ve got following error which was running fine in v1.7. I’ve got no idea what it stuck about, there is nothing changed except updating to 1.8.2, what could be possible wrong here?

fatal: [nfsserver → 127.0.0.1] =\> {‘msg’: ‘Exception: host not found: ansible\_ssh\_host’, ‘failed’: True}

Thanks.

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [January 6, 2015, 1:59am UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181/5 "2015-01-06T01:59:05Z")

</div>

I set up ansible\_ssh\_host=10.1.0.1 in my inventory file, but the function def \_get\_host(self, hostname) in inventory **init**.py checks if hostname == host.name, when the hostname is “ansible\_ssh\_host”, it cannot match and return None and exception. Is it a bug in 1.8.2?

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [January 6, 2015, 5:51pm UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181/6 "2015-01-06T17:51:53Z")

</div>

Are you able to post a small reproducer? It would help to determine if this is a bug or not.

Thanks, Toshio

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [January 7, 2015, 11:00am UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181/7 "2015-01-07T11:00:28Z")

</div>

Hi Toshio,

> |   
> |
> 
> - | - |

> Are you able to post a small reproducer? It would help to determine if this is a bug or not.

That problem only occurred on CentOS 6.5, it did not repeat in CentOS 7 and Ubuntu 14. I suspect that might be caused by different python version, CentOS 6 uses python 2.6, both CentOS 7 and Ubuntu 14 use python 2.7. It does not seem the bug in the ansible code, but it is fragile .

Anyway, the original issue still remains in v1.8.2 although Tom said it did not break in his site, I still could not get it work. Both CentOS 7 and Ubuntu 14 got the same exception at - { role: nfs-client, nfsServer: { ‘ansible\_facts’: { ‘ansible\_eth0’ : { ‘ipv4’ : { ‘address’: ‘[hce.com](http://hce.com)’ } } } } }

Thanks Toshio.

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [January 8, 2015, 12:53am UTC](https://forum.ansible.com/t/pass-dictionary-variables-to-the-role-does-not-work/17181/8 "2015-01-08T00:53:09Z")

</div>

I’ve found the dictionary variable problem, there is a task register the same variable name as follows:

- name: register the variable  
register: nfsServer  
…  
when: nfsServer is not defined

When I define the - { role: nfs-client, nfsServer: { ‘ansible\_facts’: { ‘ansible\_eth0’ : { ‘ipv4’ : { ‘address’: ‘[hce.com](http://hce.com)’ } } } } }, I thought the when checked it, the register should never be called, but no, the register is still being called, the vairable nfsServer I defined in the playbook is changed to be the registered variable which got contents of {u’skipped’: True, u’changed’: False}. If I commented the register statement out, it works.

The question is why the register can still be called even the when condition is in false status?
