Category: ansible

In this blog post I will show you a technique that can be used to parallelize any task loop in Ansible. There are fundamentally two ways in which you can parallelize operations in Ansible: Unfortunately these standard solutions have drawbacks. In order to parallelize work across several hosts, you need to have different hosts in the first place: this means that if you aim to parallelize a loop of task within a single host, you are out of luck.

The idea is to be able to create multiple virtual host copies, from your real inventory hosts, and to distribute work among them.

The only significant requirements for employing this technique is that the user must know which variables should be copied over to the virtual hosts, and that in most cases the ansible.builtin.free strategy must be used to unlock the performance gains; otherwise, Ansible will most likely serialize your loops due to long standing limitations of Ansible itself (#30816#36978).

Related Articles