# strange variable behaviour/error

**URL:** <https://forum.ansible.com/t/strange-variable-behaviour-error/32897>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [May 9, 2020, 1:55pm UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897 "2020-05-09T13:55:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfredo\_De\_Luca](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Alfredo\_De\_Luca](https://forum.ansible.com/u/Alfredo_De_Luca)\
**Post date:** [May 9, 2020, 1:55pm UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897/1 "2020-05-09T13:55:18Z")

</div>

Hi all.  
I have ansible 2.9.7 running on ubuntu. I am just running some test and one is to create an inventory by a template.  
All good except when I use the template it says

**fatal: [instance]: FAILED! =\> {“changed”: false, “msg”: “AnsibleUndefinedVariable: ‘network\_interface’ is undefined”}**

Now here is the inventory.j2 snip

[control] {{ osk\_nodes.split(',')[0] }}

[compute]  
{% for node\_ip in osk\_nodes.split(‘,’) %}  
{{node\_ip}}  
{% endfor %}

[all:vars]  
**network\_interface=eno1**

Not sure why it keep saying undefined variable. where I specifically set the network\_interface to eno1.

Any ideas/suggestions?  
Cheers

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [May 9, 2020, 3:00pm UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897/2 "2020-05-09T15:00:53Z")

</div>

Hi,

Please give us a small case with all the pieces and how you run it (ansible-playbook )… You speak about an inventory but it is a template, sound strange given like this…

---

<div class="post-metadata">

**Author:** ![Alfredo\_De\_Luca](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Alfredo\_De\_Luca](https://forum.ansible.com/u/Alfredo_De_Luca)\
**Post date:** [May 9, 2020, 4:25pm UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897/3 "2020-05-09T16:25:38Z")

</div>

Apologies if it wasn’t clear.  
So it’s a playbook that create an inventory file from a template for kolla-ansible so it can install Openstack.

here is the playbook

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 10, 2020, 11:32am UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897/4 "2020-05-10T11:32:55Z")

</div>

This list is about ansible itself, but your issue seems to be highly specific to the “kolla” framework:

[https://docs.openstack.org/project-deploy-guide/kolla-ansible/latest/](https://docs.openstack.org/project-deploy-guide/kolla-ansible/latest/)  
I would start by reaching out to that community for support first as their users will have much more experience with the mechanics of “kolla”.

---

<div class="post-metadata">

**Author:** ![Alfredo\_De\_Luca](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Alfredo\_De\_Luca](https://forum.ansible.com/u/Alfredo_De_Luca)\
**Post date:** [May 10, 2020, 5:13pm UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897/5 "2020-05-10T17:13:04Z")

</div>

I thought about writing to the community and ask…but before doing that I took the playbook and the template and create a simple project with molecule.  
Then the same issue. no kolla-ansible/kolla involved at all.  
So must be something else.

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [May 10, 2020, 5:21pm UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897/6 "2020-05-10T17:21:12Z")

</div>

OK here is the playbook. What is the complete template, the inventory you use and the command you’ve used ?

Regards,

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 10, 2020, 5:26pm UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897/7 "2020-05-10T17:26:25Z")

</div>

So far you only provided bits of information, like variables without values etc.

We can’t magically guess what your environment looks like.  
Please come up with a clear isolated, reproducible playbook, including templates, inventory, etc.

---

<div class="post-metadata">

**Author:** ![Alfredo\_De\_Luca](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Alfredo\_De\_Luca](https://forum.ansible.com/u/Alfredo_De_Luca)\
**Post date:** [May 11, 2020, 11:02am UTC](https://forum.ansible.com/t/strange-variable-behaviour-error/32897/8 "2020-05-11T11:02:28Z")

</div>

hi all.  
I figured out why I was having that issue.  
The problem was into the jinja2 templates where I found out that if I line starts with # it’s not interpreted as a comment and so why ansible kept throwing errors on undefined variable.

ISSUE

[control:vars]  
**#kolla\_external\_vip\_interface=“{{ network\_interface }}” \<------------- WRONG**

so here the playbook had issues with undefined variable (network\_interface)  
but cause for me was commented I couldn’t understand the error.

FIX  
[control:vars]  
**{#kolla\_external\_vip\_interface=“{{ network\_interface }}”##} \<--------- RIGHT**

This is a proper comment which now doesn’t appear in the target file.

Cheers
