I am spinning up new VM's using openstack heat template and get the IP list of the newly spun up VM's. I am using Ansible scripts for the same.
I am able to get the new list of IP's from the heat and I am able to deploy an app using with_items in a sequential manner.
How can I do the deployments in parallel using Ansible scripts so that the total deployment time on "n" servers is same as that of One server.
One options is to create a dynamic inventory script that will fetch the instance ips from Heat and make them available to Ansible. Consider a Heat template that looks like this:
This will define three nova instances, where each instance is defined as:
After deploying this stack, we can get a list of public ips like this:
We can write a simple Python script to implement the dynamic inventory interface:
We can test that out to see that it works:
Assume that we have the following Ansible playbook:
This will run the
sleep 60
command on each host. That should take around one minute to run things in parallel, and around three minutes if things are serialized.Testing things out:
As you can see, the command is executing in parallel on all three hosts, which is the behavior you were looking for (but be aware of this thread, which describes situations in which Ansible will serialize things without telling you).