Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jinja template evaluation fails on undefined variables even when error_on_undefined_vars = False #4025

Closed
rrtj3 opened this issue Sep 5, 2013 · 0 comments
Labels
bug This issue/PR relates to a bug.

Comments

@rrtj3
Copy link
Contributor

rrtj3 commented Sep 5, 2013

I have some jinja templates that I make use of variables that may or may not be defined, but have Jinja if/elif statements that deal with this correctly. Using git bisect I was able to track down the first bad commit to this:

62b39d3 is the first bad commit
commit 62b39d3
Author: Michael DeHaan michael@ansibleworks.com
Date: Sun Jul 21 08:52:00 2013 -0400

Fix for saving conditionals in variable expressions.

After this commit creation of the template fails with this error:

fatal: [127.0.0.1] => {'msg': "One or more undefined variables: 'dict' object has no attribute 'facts'", 'failed': True}
fatal: [127.0.0.1] => {'msg': "One or more undefined variables: 'dict' object has no attribute 'facts'", 'failed': True}

even when the "error_on_undefined_vars = False" is set in the ansible.cfg file. Here is an example of such 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 %}

Please let me know if you need any more information.

@jimi-c jimi-c closed this as completed in 294451d Sep 9, 2013
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants