Question:
Is it possible to run ansible playbook, which looks like this (it is an example from this site: http://docs.ansible.com/playbooks_roles.html):
1 2 3 4 5 6 7 8 9 10 11 12 |
- name: this is a play at the top level of a file hosts: all remote_user: root tasks: - name: say hi tags: foo shell: echo "hi..." - include: load_balancers.yml - include: webservers.yml - include: dbservers.yml |
in multithread mode?
I want to run three “includes” in the same time (it is deploying to different hosts anyway)
Is it possible?
Answer:
I played a long time with things like ls -1 | xargs -P
to parallelize my playbooks runs. But to get a prettier display, and simplicity I wrote a simple Python tool to do it, ansible-parallel.
It goes like this:
1 2 3 |
pip install ansible-parallel ansible-parallel *.yml |
To answer precisely to the original question (how to run some tasks first, and the rest in parallel), it can be solved by removing the 3 includes and running:
1 2 3 |
ansible-playbook say_hi.yml ansible-parallel load_balancers.yml webservers.yml dbservers.yml |