0

If I'm to declare following variable under my "host_vars/host_name" or "group_vars/group_name" folders - I'll end up with undefined variable.

At the same time if I'm to declare the same in my Inventory file under any of my ":var" group variables I can call for my variable just fine.

I was wondering if this is something expected? Is anyone else seeing something similar? Facts lookup is enabled of course.

Here is my example:

network_mask = "{{ ansible_eth1.ipv4.network }}/{{ ansible_eth1.ipv4.netmask }}"
Sarabjit Singh
  • 1,814
  • 1
  • 17
  • 28

1 Answers1

0

Files in host_vars and group_vars are supposed to be YAML or JSON:

These variable files are in YAML format. Valid file extensions include ‘.yml’, ‘.yaml’, ‘.json’, or no file extension

So change to:

network_mask: "{{ ansible_eth1.ipv4.network }}/{{ ansible_eth1.ipv4.netmask }}"
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • Thank you for your help! I should have been more specific though. Earlier the same YAML "key:value" syntax didn't work for me. As it turns out I'm facing a very different issue here. – user7509807 Feb 04 '17 at 08:32
  • The thing is that I keep my playbooks in a separate folder - this brakes variable lookup in host_vars/group_vars folders. It seem that my only option is to copy these folder(s) into corresponding playbook folder(s) - not very elegant but I'm not aware of a better solution at this stage. In case if it is of any interest further info could be located here: (https://github.com/ansible/ansible/issues/16878) – user7509807 Feb 04 '17 at 08:39