一般情况下, ansible会同时在所有服务器上执行用户定义的操作, 但是用户可以通过serial参数来定义同时可以在多少太机器上执行操作.
[root@web2 asynctest]# cat Concurrent.yml
---
- hosts: cluster
tasks:
- shell: date
[root@web2 asynctest]# ansible-playbook Concurrent.yml
PLAY [cluster] *****************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************
ok: [192.168.222.140]
ok: [192.168.222.141]
ok: [192.168.222.142]
ok: [192.168.222.139]
TASK [command] *****************************************************************************************************
changed: [192.168.222.140]
changed: [192.168.222.139]
changed: [192.168.222.141]
changed: [192.168.222.142]
PLAY RECAP *********************************************************************************************************
192.168.222.139 : ok=2 changed=1 unreachable=0 failed=0
192.168.222.140 : ok=2 changed=1 unreachable=0 failed=0
192.168.222.141 : ok=2 changed=1 unreachable=0 failed=0
192.168.222.142 : ok=2 changed=1 unreachable=0 failed=0
[root@web2 asynctest]# cat Concurrent.yml
---
- hosts: cluster
serial: 2
tasks:
- shell: date
[root@web2 asynctest]# ansible-playbook Concurrent.yml
PLAY [cluster] *****************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************
ok: [192.168.222.140]
ok: [192.168.222.139]
TASK [command] *****************************************************************************************************
changed: [192.168.222.140]
changed: [192.168.222.139]
PLAY [cluster] *****************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************
ok: [192.168.222.141]
ok: [192.168.222.142]
TASK [command] *****************************************************************************************************
changed: [192.168.222.141]
changed: [192.168.222.142]
PLAY RECAP *********************************************************************************************************
192.168.222.139 : ok=2 changed=1 unreachable=0 failed=0
192.168.222.140 : ok=2 changed=1 unreachable=0 failed=0
192.168.222.141 : ok=2 changed=1 unreachable=0 failed=0
192.168.222.142 : ok=2 changed=1 unreachable=0 failed=0
因为ansible默认为5的并发值,后面改为2了就成了一次并发2个主机任务
serial参数在ansible-1.8以后就开始支持百分比.
默认情况下, 只要group中还有server没有失败, ansible就是继续执行tasks.实际上, 用户可以通过"max_fail_percentage" 来定义, 只要超过max_fail_percentage台的server失败, ansible 就可以中止tasks的执行.
---
- hosts: cluster
max_fail_percentage: 25
serial: 1
tasks:
- shell: date
实际失败机器必须大于这个百分比时, tasks才会被中止. 等于时是不会中止tasks的.
上面失败比例为25%现在4台,失败1台是不会中止的,达到2太失败才会中止任务