Ansible:如何将角色并行部署到不同的主机
Ansible: How can I deploy the roles on paralel to different hosts
我有下一个 main.yml,我想 运行 角色一个接一个但并行地用于不同的主机:
例如,首先我想 运行 "cluster-prerequisites" 在所有主机上并行角色,当它完成 运行 "docker" 角色等..
- hosts: masters:private_agent:public_agent
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: cluster_prerequisites
- hosts: bootstrap:masters:private_agent:public_agent
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: docker
- hosts: bootstrap
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: prepare_bootstrap
- hosts: masters
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: run_masters
- hosts: private_agent
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: run_private_agents
- hosts: public_agent
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: run_public_agents
By default, Ansible will try to manage all of the machines referenced in a play in parallel. For a rolling updates use case, you can define how many hosts Ansible should manage at a single time by using the serial
keyword...
因此,如果您从游戏中删除 serial: 1
,Ansible 将 运行 在游戏中的所有主机上并行执行任务。
通过设置 serial: 1
,您告诉 Ansible 一台接一台地接管主机,只有当上一个主机的所有任务都完成时才移动到下一个主机。
通常你想在一堆后端服务器上做串行 运行s 以批量更新它们以防止服务停机,因为部分服务器仍然可以服务客户端的请求。
我有下一个 main.yml,我想 运行 角色一个接一个但并行地用于不同的主机: 例如,首先我想 运行 "cluster-prerequisites" 在所有主机上并行角色,当它完成 运行 "docker" 角色等..
- hosts: masters:private_agent:public_agent
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: cluster_prerequisites
- hosts: bootstrap:masters:private_agent:public_agent
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: docker
- hosts: bootstrap
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: prepare_bootstrap
- hosts: masters
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: run_masters
- hosts: private_agent
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: run_private_agents
- hosts: public_agent
remote_user: "{{user}}"
become: True
serial: 1
roles:
- role: run_public_agents
By default, Ansible will try to manage all of the machines referenced in a play in parallel. For a rolling updates use case, you can define how many hosts Ansible should manage at a single time by using the
serial
keyword...
因此,如果您从游戏中删除 serial: 1
,Ansible 将 运行 在游戏中的所有主机上并行执行任务。
通过设置 serial: 1
,您告诉 Ansible 一台接一台地接管主机,只有当上一个主机的所有任务都完成时才移动到下一个主机。
通常你想在一堆后端服务器上做串行 运行s 以批量更新它们以防止服务停机,因为部分服务器仍然可以服务客户端的请求。