我有一本剧本,其中我更新了3台机器的集群。 我使用“ serial:1”来一次运行一台计算机。 我需要的是每次重新启动后都需要重新启动其他两台计算机上的服务列表。 我该怎么做?
我所拥有的样品:
- name: "Stop from booting and stop service"
service:
name: "{{item}}"
enabled: no
state: stopped
loop: "{{service_list}}"
when: standby.changed
register: stop_service
##Reboot
- name: "Reboot Server"
reboot:
pre_reboot_delay: 120
post_reboot_delay: 60
reboot_timeout: 600
when: stop_service.changed
register: reboot_1
##Upgrade
- name: "Upgrade SO"
apt:
update_cache: yes
upgrade: dist
when: reboot_1.changed
register: upgrade
##Reboot
- name: "Reboot Server"
reboot:
pre_reboot_delay: 60
post_reboot_delay: 60
reboot_timeout: 600
when: upgrade.changed
register: reboot_2
##Start Services
- name: "Start service and enable start on booting"
service:
name: "{{item}}"
state: started
enabled: yes
loop: "{{service_list}}"
when: reboot_2.changed
register: start_service
- name: "Restart service on other machines"
service:
name: "{{item}}"
state: restarted
loop: "{{service_list}}"
delegate_to: other machines....
感谢您的帮助!
答案 0 :(得分:0)
这不能很好地扩展,并且对于转移库存也不是动态的,但是对于仅几台服务器,您可以执行以下操作,并且仅为要配置的每台服务器构建一个:
- name: "Restart service on other machines"
service:
name: "{{item}}"
state: restarted
loop: "{{service_list}}"
delegate_to: server1
when: inventory_hostname != 'server1'
由于您已经以串行方式运行它们,因此当您在server1上时,其条件将失败,但是它将传递给服务器2和3,并将该任务委托给它们。