undefined variables

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.

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?

Hi James, thanks for responding.

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.

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.

Do you mean to say when error_on_undefined_vars=False

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

?

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

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

Here is the git bisect output:

62b39d3de535370ae7e98a3fbdcd1799819523ee is the first bad commit
commit 62b39d3de535370ae7e98a3fbdcd1799819523ee
Author: Michael DeHaan <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.

Github issue:

https://github.com/ansible/ansible/issues/4025

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.

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.