strange variable behaviour/error

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

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…

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

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/
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”.

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.

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

Regards,

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.

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