ec2 facts from templates not rendering

hi all,

I have a roles/common/templates/instance.properties.j2 fiel with the bellow contents :

HOSTNAME = {{ ansible_fqdn }}
PUBLIC_IP = {{ ansible_ec2_public_ipv4 }}
PRIVATE_IP = {{ ansible_eth0.ipv4.address }}
AVAIL_ZONE = {{ ansible_ec2_placement_availability_zone }}
server.id= {{ ansible_ec2_instance_id }}

Unfortunately only the HOSTNAME and PRIVATE_IP are rendering, the rest of the values are blank :

HOSTNAME = ip-10-34-149-173.eu-west-1.compute.internal
PUBLIC_IP =
PRIVATE_IP = 10.34.149.173
AVAIL_ZONE =
server.id=

Any clue ?

What does the play look like?

Brian Coca

roles/common/tasks/main.yml :

That is just the role tasks, I was asking for the play so I could see your fact gathering

Brian Coca

isn’t the fact gathering enabled by default ?

While generic Linux fact gathering is enabled by default, the ec2 fact module must be explicitly called.

cheers, it’s working now using :

- name: Gathering ec2 facts
  ec2_facts:

does the ec2 facts has any performance impact ?

How do you mean? Do you mean time to run? The ec2_facts module runs on the instance to gather info from the metadata service and then returns this. If you have lots of hosts, it could of course take some time :slight_smile:

It should be negligible.

Parallelism can naturally be increased, along with everything else in ansible, by specifying a higher value for --forks.

This is true for all task types and not just this.