how to set defaults for ec2_facts when not in AWS ???

Hi,

We have our ansible playbooks working with no problem to deploy our servers in Amazon ec2. One of the ansible modules we use is the ec2_facts in order to configure some files , as for example we use the {{ ansible_ec2_placement_availability_zone }} value.

There is a chance we need to deploy some of our servers on a different cloud provider or on bare metal servers, in that case the ec2_facts module will fail.

I know I could just add an ignore_errors on the ec2_facts task but we need to make sure when in AWS environment the ec2_facts are populated successfully so I’m wondering how can we set default values when we run a playbook in a non AWS environment ?

For example I would like to set the bellow without using “when:” or specifying in advance if the inventory hosts are in ec2 or not :

ansible_ec2_placement_availability_zone : NA

Any ideas ?

Regards,
N.

“There is a chance we need to deploy some of our servers on a different cloud provider or on bare metal servers, in that case the ec2_facts module will fail.”

I would consider constraining the ec2 configuration items to a specific role and maybe do:

  • hosts: ec2_webservers
    roles: