Ansible:同时部署在多台主机上 [英] Ansible: deploy on multiple hosts in the same time

查看:28
本文介绍了Ansible:同时部署在多台主机上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以运行 ansible playbook,它看起来像这样(这是来自此站点的示例:http://docs.ansible.com/playbooks_roles.html):

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

多线程模式?

我想同时运行三个包含"(无论如何它都部署到不同的主机),如下图所示:

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

有可能吗?

推荐答案

我玩了很长时间,比如 ls -1 |xargs -P 并行化我的剧本运行.但是为了获得更漂亮的显示和简单性,我编写了一个简单的 Python 工具来实现它,ansible-parallel.

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.

事情是这样的:

pip install ansible-parallel
ansible-parallel *.yml

要准确回答原始问题(如何先运行一些任务,然后并行运行其余任务),可以通过删除 3 个包含并运行来解决:

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:

ansible-playbook say_hi.yml
ansible-parallel load_balancers.yml webservers.yml dbservers.yml

这篇关于Ansible:同时部署在多台主机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆