# undefined variables

**URL:** <https://forum.ansible.com/t/undefined-variables/13419>\
**Category:** Ansible Project\
**Created:** [September 4, 2013, 7:23pm UTC](https://forum.ansible.com/t/undefined-variables/13419 "2013-09-04T19:23:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 4, 2013, 7:23pm UTC](https://forum.ansible.com/t/undefined-variables/13419/1 "2013-09-04T19:23:48Z")

</div>

I make extensive use of templates and and am testing the “soon to be released” 1.3 against some of my playbooks and am running into this error:

fatal: [127.0.0.1] =\> {‘msg’: “One or more undefined variables: ‘dict’ object has no attribute ‘facts’”, ‘failed’: True}

I set:

error\_on\_undefined\_vars = False

in the ansible.cfg but this doesn’t seem to be having any effect. Am I missing something obvious?

I have multiple “if variable is defined” type loops in my jinja template and I’m guessing this is what it’s dying on. Or have the internal datastructures changed:

Example of template:

% for nic in virtual\_machine.vm\_nic|dictsort %}  
{% if nic[1].kickstart == “yes” %}  
{% if loop.index0 == 0 %}  
network --onboot yes --device=eth0 --bootproto=static --ip={{ eth0.facts.network\_ipaddress }} --netmask={{ eth0.facts.network\_netmask }} --gateway={{ eth0.facts.network\_gateway }} --nameserver={{ eth0.facts.network\_nameservers[0] }} --noipv6 --activate  
{% elif loop.index0 == 1 %}  
network --onboot yes --device=eth1 --bootproto=static --ip={{ eth1.facts.network\_ipaddress }} --netmask={{ eth1.facts.network\_netmask }} --gateway={{ eth1.facts.network\_gateway }} --nameserver={{ eth1.facts.network\_nameservers[0] }} --noipv6 --activate  
{% elif loop.index0 == 2 %}  
network --onboot yes --device=eth2 --bootproto=static --ip={{ eth2.facts.network\_ipaddress }} --netmask={{ eth2.facts.network\_netmask }} --gateway={{ eth2.facts.network\_gateway }} --nameserver={{ eth2.facts.network\_nameservers[0] }} --noipv6 --activate  
{% endif %}  
{% endif %}  
{% endfor %}

This works fine in 1.2.

Thanks for any pointers.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 4, 2013, 8:58pm UTC](https://forum.ansible.com/t/undefined-variables/13419/2 "2013-09-04T20:58:48Z")

</div>

It looks like there is no .facts key in one or more of the ethX variables you’re using. If it were related to the error\_on\_undefined\_vars setting you’d be getting a different error. Are these supposed to be based on ansible facts?

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 4, 2013, 9:11pm UTC](https://forum.ansible.com/t/undefined-variables/13419/3 "2013-09-04T21:11:37Z")

</div>

Hi James, thanks for responding.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 4, 2013, 9:21pm UTC](https://forum.ansible.com/t/undefined-variables/13419/4 "2013-09-04T21:21:30Z")

</div>

Ahh I see, since you said error\_on\_undefined\_vars=False didn’t resolve the issue I didn’t think it would be related. That tells me there may be something else going on there in the template.

In 1.3, the only real change was to flip the default of that flag - nothing else really changed. What I would recommend is using “git bisect” if you know how to try and identify the commit that really broke things. If you’re not familiar with bisect and want me to walk you through it, let me know (I can email you off list or you can hop on IRC, my nick there is jimi\_c). If you can also open a github issue for this, I’d appreciate it.

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 4, 2013, 10:49pm UTC](https://forum.ansible.com/t/undefined-variables/13419/5 "2013-09-04T22:49:24Z")

</div>

Thanks James, I’ll see what I can find with git bisect. If I can’t I’ll ping you for some help and/or create a github issue.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 4, 2013, 11:06pm UTC](https://forum.ansible.com/t/undefined-variables/13419/6 "2013-09-04T23:06:59Z")

</div>

Do you mean to say when error\_on\_undefined\_vars=False

you still get the message “One or more undefined variables”

?

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 4, 2013, 11:11pm UTC](https://forum.ansible.com/t/undefined-variables/13419/7 "2013-09-04T23:11:56Z")

</div>

> Do you mean to say when error\_on\_undefined\_vars=False
> 
> you still get the message "One or more undefined variables"
> 
> ?

Yes, I still get the error when error\_on\_undefined\_vars = False.

Romeo

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 5, 2013, 12:30am UTC](https://forum.ansible.com/t/undefined-variables/13419/8 "2013-09-05T00:30:42Z")

</div>

Yay for git bisect. Great to know about that. Was able to track down the issue to this commit:

[https://github.com/ansible/ansible/commit/62b39d3de535370ae7e98a3fbdcd1799819523ee](https://github.com/ansible/ansible/commit/62b39d3de535370ae7e98a3fbdcd1799819523ee)

Here is the git bisect output:

62b39d3de535370ae7e98a3fbdcd1799819523ee is the first bad commit  
commit 62b39d3de535370ae7e98a3fbdcd1799819523ee  
Author: Michael DeHaan \<[michael@ansibleworks.com](mailto:michael@ansibleworks.com)\>

Fix for saving conditionals in variable expressions.

:100644 100644 5aa07bb62ba827db60b8484f09f153397fd77814 e88e88ae128d70fe1f0c3e8c042c2e5c857ad050 M CHANGELOG.md  
:040000 040000 9f994cca84c9496eed8de7317be052276de2bc73 10f3fe830ec9f12b3986aaa3510d2333c35d3b45 M lib

I’ll create a github issue also.

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 5, 2013, 12:39am UTC](https://forum.ansible.com/t/undefined-variables/13419/9 "2013-09-05T00:39:59Z")

</div>

Github issue:

[https://github.com/ansible/ansible/issues/4025](https://github.com/ansible/ansible/issues/4025)

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 5, 2013, 12:43am UTC](https://forum.ansible.com/t/undefined-variables/13419/10 "2013-09-05T00:43:48Z")

</div>

Yeah bisect is awesome, really makes it easy to isolate the problem. We’ll take a look at this, but is it also possible for you to share your fact module or any playbooks you’re using to help us replicate this error? Feel free to redact anything you need to in order to share.

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 5, 2013, 12:53am UTC](https://forum.ansible.com/t/undefined-variables/13419/11 "2013-09-05T00:53:38Z")

</div>

> Yeah bisect is awesome, really makes it easy to isolate the problem. We'll  
> take a look at this, but is it also possible for you to share your fact  
> module or any playbooks you're using to help us replicate this error? Feel  
> free to redact anything you need to in order to share.

Sure, can do. I'm going to email it to you off list though.
