Guidance on deploying with Ansible

I think I have an idea about how to do this, but I wanted some guidance from the Ansible community:

What I would like to do is the following:

  1. Run ansible-playbook
  2. Ensure that there are X nodes in EC2 matching some criteria (an instance tag would be best), and create additional instances as necessary to bring the count up to X
  3. Add each of the instance found/created to the set of hosts or the play
  4. Add host variables based on instance tags on each of the instances
  5. Run my play (and all associated roles) against that list of hosts built from the previous steps.

Thanks for the help.

Take a look at “exact_count” in the Ec2 module for #2, as combined with the add_host module.

This is a pretty common pattern.

With add_host you can throw the machine into a group, and the group_vars files will pick up and be applied.

Any specific questions?

Awesome, this is a great start.

2 questions off the top of my head:

  1. Because I am using ansible-playbook, where do I put these steps such that they run before the roles do so that all the machines are created, running, and in the hosts for the play? Would I have them in the playbook file before the -roles section?

  2. Can I take the tags from the ec2 instances and add them as variables on the hosts as I add each instance to the hosts for the play? I have host-specific configuration that would be perfect to put in the instance tags

Thanks for you help.