Vasyl Slobodyan
Vasyl Slobodyan

Reputation: 21

ansible parallel deployment

After days of research and hitting the brick wall deciding to ask here: Is it possible to deploy in parallel using single ansible playbook on aws. At the moment deploying EC2 instance takes around 5 minutes for us while RDS takes about 15-20. Is there a way how to deploy all the EC2 instances and RDS instance in parallel. Thanks in advance for the help. Update: Or is there a way for two tasks to be performed at the same time within one host and one playbook

Upvotes: 1

Views: 765

Answers (1)

phill.tomlinson
phill.tomlinson

Reputation: 1086

Have a look into a tool called Packer

It states it can "create machine images for multiple platforms in parallel". You can then call ansible to provision the EC2.

If creating a number of similar EC2 instances then try specifying the count property as its within the same task:

http://docs.ansible.com/ansible/ec2_module.html

count no | 1 | number of instances to launch

EDIT

In response to the comment can you not set "wait: no" (wait for the AMI to be in state 'available' before returning) when creating the EC2's. You can still register the instances as a variable but ansible will move onto the next task for example the RDS's. To wait for both groups to complete before exiting use a wait_for module and loop through the items for example:

- name: Wait for the instances to boot by checking the ssh port
   wait_for: host={{item.private_ip}} port=22 delay=60 timeout=320 state=started
   with_items: ec2.instances

This will spin up all instances concurrently in the background and enable you to provision the EC2's first while waiting for the RDS's to spin up.

Upvotes: 1

Related Questions