Ansible:同时部署在多个主机上 [英] Ansible: deploy on multiple hosts in the same time
问题描述
是否可以运行如下所示的ansible剧本(这是该站点的示例: 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
在多线程模式下?
我想同时运行三个"includes"(无论如何将其部署到不同的主机),如下图所示:
http://www.gliffy.com/go/publish/5267618
有可能吗?
从Ansible 2.0开始,剧本上似乎有一个名为strategy
的选项.将策略设置为free
时,剧本在每个主机上播放任务,而无需等待其他主机.参见 http://docs.ansible.com/ansible/playbooks_strategies.html .>
看起来像这样(取自上面的链接):
- hosts: all
strategy: free
tasks:
...
请注意,我没有检查此内容,而我非常是Ansible的新手.我只是对做您描述的事情感到好奇,并且碰巧发现了这种策略性的事情.
这似乎并不是您要尝试执行的操作.如下所述,也许异步任务"更合适: http://docs.ansible.com/ansible/playbooks_async.html .
这包括在任务上指定async
和poll
.以下摘自我提到的第二个链接:
- name: simulate long running op, allow to run for 45 sec, fire and forget
command: /bin/sleep 15
async: 45
poll: 0
我想如果任务很长,您可以指定更长的async
次.您可能可以通过这种方式定义三个并发任务.
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?
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.
这篇关于Ansible:同时部署在多个主机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!