strange variable behaviour/error

35 views
Skip to first unread message

Alfredo De Luca

unread,
May 9, 2020, 9:55:26 AM5/9/20
to ansible...@googlegroups.com
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 

<SNIP>
[control]
{{ osk_nodes.split(',')[0] }}

[compute]
{% for node_ip in osk_nodes.split(',') %}
{{node_ip}}
{% endfor %}

[all:vars]
network_interface=eno1
<SNIP>

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

Any ideas/suggestions?
Cheers




--
/Alfredo

Jean-Yves LENHOF

unread,
May 9, 2020, 11:01:08 AM5/9/20
to ansible...@googlegroups.com

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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAAWpFTH6R_mpCgd%2BW3ubGnPrJGmy12a-gJAhPZ2-WtTtZSHuGA%40mail.gmail.com.

Alfredo De Luca

unread,
May 9, 2020, 12:26:09 PM5/9/20
to ansible...@googlegroups.com
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

---
- name: TEMPLATES
  file:
      path: "{{ deploy_env }}/my_envs/openstack/{{ deploy_env }}"
      state: directory
      mode: 0755

- name: Create inventory file from a template
  template:
      src: templates/osk_inventory.j2
      dest: "{{ deploy_env }}/my_envs/openstack/{{ deploy_env }}/osk_inventory_{{ deploy_env }}"
      owner: root
      group: root

--
/Alfredo

Dick Visser

unread,
May 10, 2020, 7:33:26 AM5/10/20
to ansible...@googlegroups.com
This list is about ansible itself, but your issue seems to be highly specific to the "kolla" framework:
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".



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Alfredo De Luca

unread,
May 10, 2020, 1:13:34 PM5/10/20
to ansible...@googlegroups.com
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.






--
/Alfredo

Jean-Yves LENHOF

unread,
May 10, 2020, 1:21:27 PM5/10/20
to ansible...@googlegroups.com

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

Regards,

Dick Visser

unread,
May 10, 2020, 1:26:51 PM5/10/20
to ansible...@googlegroups.com
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.




Alfredo De Luca

unread,
May 11, 2020, 7:03:05 AM5/11/20
to ansible...@googlegroups.com
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







--
/Alfredo

Reply all
Reply to author
Forward
0 new messages