6.ansible并发

一般情况下, 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太失败才会中止任务














 

转载于:https://my.oschina.net/eddylinux/blog/1503302

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值