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

91 views
Skip to first unread message

Nicolas G

unread,
May 20, 2014, 10:59:33 AM5/20/14
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
May 21, 2014, 6:00:39 PM5/21/14
to ansible...@googlegroups.com
 "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:
     - ec2_config
     - other_config

And in another playbook, maybe you apply all roles but the ec2 step.

If you wanted a fact on EC2 in a different variable, you could use the "set_fact" module to assign it from a different source, and leave the other roles independent.

Altenratively, you could have steps like:

when: ansible_ec2_blah is defined

or "is not defined"

using conditionals.



--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/dea52314-0a99-48e1-923a-9eb85ab14aa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages