我喜欢升级我的MongoDB,我创建了这样一个剧本:
- hosts: all
tasks:
- name: Shutdown mongod service
service:
name: mongod
state: stopped
- name: Replace MongoDB binaries
yum:
name: mongod-org
state: present
- name: Start mongod service
service:
name: mongod
state: started
问题是,ansible首先在所有主机上停止服务,这使得我的应用程序不可用,然后对all进行升级,最后在所有主机上再次启动服务。
如何为每个主机依次运行这些任务,即
service
我尝试过使用block
和include_tasks
,但结果总是这样:
TASK [Shutdown mongod service] ***********************************************
changed: [d-mipmdb-cfg-01]
changed: [d-mipmdb-cfg-03]
changed: [d-mipmdb-cfg-02]
TASK [Replace MongoDB binaries] ******************************************************************************
changed: [d-mipmdb-cfg-01]
changed: [d-mipmdb-cfg-03]
changed: [d-mipmdb-cfg-02]
TASK [Start mongod service] ******************************************************************************
changed: [d-mipmdb-cfg-03]
changed: [d-mipmdb-cfg-01]
changed: [d-mipmdb-cfg-02]
发布于 2020-09-24 06:10:44
https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html
默认情况下,Ansible与您在每次播放的hosts:
字段中设置的模式中的所有主机并行运行。如果希望一次只管理几台机器,例如在滚动更新期间,可以使用serial
关键字定义一次应该管理多少主机:
- name: test play
hosts: webservers
serial: 2
gather_facts: False
tasks:
- name: first task
command: hostname
- name: second task
command: hostname
https://stackoverflow.com/questions/64048208
复制相似问题