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):
- 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), like in this diagram:
http://www.gliffy.com/go/publish/5267618
Is it possible?
Ansible's parallel processes are known as forks, and the default number of forks is five. The more forks you set, the more resources are used on the Ansible control node.
One of the best things about Ansible is its ability to operate in parallel across multiple hosts. The number of hosts it can operate on at once depends on multiple factors. The largest factor is the forks parameter. This parameter has a default of 5, which will limit Ansible to operating on only five hosts at one time.
Ansible is not designed to run multiple playbooks at the same time in one process - for example, because the tasks differ from playbook to playbook and there is no step "taskA" in playbook1 and playbook2 at the same time. You need to run every playbook in one separate process (like with ansible-playbook ... & ).
Ansible playbooks are written in YAML format, and they contain multiple tasks executed in sequential order.
As of Ansible 2.0 there seems to be an option called strategy
on a playbook. When setting the strategy to free
, the playbook plays tasks on each host without waiting to the others. See http://docs.ansible.com/ansible/playbooks_strategies.html.
It looks something like this (taken from the above link):
- hosts: all strategy: free tasks: ...
Please note that I didn't check this and I'm very new to Ansible. I was just curious about doing what you described and happened to come acroess this strategy thing.
EDIT:
It seems like this is not exactly what you're trying to do. Maybe "async tasks" is more appropriate as described here: http://docs.ansible.com/ansible/playbooks_async.html.
This includes specifying async
and poll
on a task. The following is taken from the 2nd link I mentioned:
- name: simulate long running op, allow to run for 45 sec, fire and forget command: /bin/sleep 15 async: 45 poll: 0
I guess you can specify longer async
times if your task is lengthy. You can probably define your three concurrent task this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With