【发布时间】:2020-06-14 21:15:14
【问题描述】:
我有一个用例,我想在多个集群中执行滚动重启。作为第一步,我创建了一个任务以在传递给任务的主机上串行执行,该任务将一次执行重新启动一个节点。目前,假设所有集群中的节点总数为 n 并且节点重启的时间恒定,则节点重启需要 O(n) 时间。我想优化这个ansible作业的执行,以便重启节点的任务在集群中串行执行,但在集群中并行执行,从而导致有效的重启时间与集群中的最大主机数成正比。给定库存示例 -
[Cluster_1]
host_1_a
host_1_b
[Cluster_2]
host_2_a
host_2_b
[Cluster_3]
host_3_a
host_3_b
host_3_c
当前执行时间是 7*(reboot_time),我想优化到 3*(reboot_time)。我不确定这是否可能在 ansible 中,并欢迎任何建议。谢谢!
Ansible playbook 重启服务:
- name: Rolling reboot
hosts: all
serial: 1
gather_facts: no
tasks:
- name: stop service
service:
name: xyz
state: stopped
- name: start service
service:
name: xyz
state: started
- name: wait for service to start
uri:
url: "http://localhost:8081/node-health"
method: GET
register: http_status
until: http_status.status == 200
retries: 60
delay: 10
【问题讨论】:
-
您能否举一个当前在所有主机之间进行连续播放的示例剧本?
-
不确定这是否对您有帮助,但请注意,串行不仅仅是是/否,您还可以每批次拥有多个主机,或者使用数组和百分比控制批次: docs.ansible.com/ansible/latest/user_guide/…
-
@AndyShinn 添加了剧本
标签: ansible ansible-2.x ansible-inventory ansible-facts ansible-template