jpisaniello
Cadet
Cadet
  • 894 Views

DO407 - jinja templating error?

Jump to solution

Hello All,

I have seen a post or two about this already, but there hasn't been any real solution proposed.

 

The following is given as a template to generate /etc/hosts:

{% for host in groups['all'] %}
{{ hostvars[host]['ansible_facts']['default_ipv4']['address'] }} {{ hostvars[host]['ansible_facts']['fqdn'] }} {{ hostvars[host]['ansible_facts']['hostname'] }}
{% endfor %}

However, after running this is seems that I receive "AnsibleUndefinedVariable: 'dict object' has no attribute 'default_ipv4'".

 

What is the confusion here? How else would one be able to easily generate an /etc/hosts file using a template?

 

Thanks

Labels (1)
0 Kudos
1 Solution

Accepted Solutions
jpisaniello
Cadet
Cadet
  • 881 Views

Re: DO407 - jinja templating error?

Jump to solution

It looks like I was specifying  a specific group of hosts to move this template to... This can't be done since we haven't gathered facts for all of the hosts, only the ones in which we run our play against.. oops

View solution in original post

0 Kudos
Reply
Loading...
1 Reply
jpisaniello
Cadet
Cadet
  • 882 Views

Re: DO407 - jinja templating error?

Jump to solution

It looks like I was specifying  a specific group of hosts to move this template to... This can't be done since we haven't gathered facts for all of the hosts, only the ones in which we run our play against.. oops

View solution in original post

0 Kudos
Reply
Loading...
Join the discussion
You must log in to join this conversation.