Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: deploy on multiple hosts in the same time

Tags:

ansible

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?

like image 941
sebaszw Avatar asked Jan 16 '14 10:01

sebaszw


People also ask

Does Ansible run tasks in parallel?

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.

How many hosts can Ansible manage?

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.

Can I run multiple Ansible playbooks in parallel?

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 ... & ).

Does Ansible work in sequential manner?

Ansible playbooks are written in YAML format, and they contain multiple tasks executed in sequential order.


1 Answers

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.

like image 155
Amir Eldor Avatar answered Oct 03 '22 05:10

Amir Eldor