I have a huge ansible playbook and I have a task, which is using an array (from values) and run the same command for each element in array.
For example (this is just example, I know that I can use one line command!):
packages:
vim:
dev:
version: x.x
qa:
version: x.x
redis:
dev:
version: x.x
qa:
version: x.x
...
And I have a task which is installing these packages:
- name: Install Packages
include_tasks: tasks/install-packages.yml
loop: "{{ lookup('dict', packages) }}"
loop_control:
loop_var: item
and
- name: "Install {{ item.key }} package"
command: >
apt-get install {{ item.key }} ...
environment:
...
retries: 3
delay: 5
register: result
until: result.rc == 0
My question is - is it possible to run the last step in threads?
As I understand - first of all I need to split packages array and run task in async mode.
In this example - apt-get install vim and apt-get install redis should start installing simultaneously.
Is it possible? Or maybe there can be some another solution?
The main goal of it - speed up package installation (for this example).