使用命令查看当前支持的strategy 列表及其描述
ansible-doc -t strategy -l
debug Executes tasks in interactive debug session
free Executes tasks without waiting for all hosts
host_pinned Executes tasks on each host without interruption
linear Executes tasks in a linear fashion is default
liner 每个task 顺序执行,例如fork=5 我们有10个主机需要执行当前playbook 那么只能10个主机都执行了task1 之后才会往下走新的任务
free 区别于上者,task执行不需要等待所有主机执行完毕以后,再往下进行执行
host_pinned 和free模式比较类似 但是输出结果比较直观
例子
- hosts: all tasks: - name: sleep 1 shell: sleep 1 - name: success shell: echo success linear 模式下 PLAY [all] **************************************************************************************************************************************************************** Friday 26 June 2020 12:54:18 +0800 (0:00:00.083) 0:00:00.083 *********** TASK [Gathering Facts] **************************************************************************************************************************************************** ok: [192.168.122.10] ok: [192.168.122.11] ok: [192.168.122.12] ok: [192.168.122.13] Friday 26 June 2020 12:54:20 +0800 (0:00:01.946) 0:00:02.030 *********** TASK [sleep 1] ************************************************************************************************************************************************************ changed: [192.168.122.10] changed: [192.168.122.11] changed: [192.168.122.12] changed: [192.168.122.13] Friday 26 June 2020 12:54:24 +0800 (0:00:04.508) 0:00:06.539 *********** TASK [success] ************************************************************************************************************************************************************ changed: [192.168.122.10] changed: [192.168.122.11] changed: [192.168.122.12] changed: [192.168.122.13] PLAY RECAP **************************************************************************************************************************************************************** 192.168.122.10 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.11 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.12 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.13 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 Friday 26 June 2020 12:54:25 +0800 (0:00:00.424) 0:00:06.964 *********** =============================================================================== sleep 1 ------------------------------------------------------------------------------------------------------------------------------------------------------------ 4.51s Gathering Facts ---------------------------------------------------------------------------------------------------------------------------------------------------- 1.95s success ------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.42s free 模式下 PLAY [all] **************************************************************************************************************************************************************** Friday 26 June 2020 12:54:44 +0800 (0:00:00.128) 0:00:00.128 *********** Friday 26 June 2020 12:54:44 +0800 (0:00:00.011) 0:00:00.139 *********** Friday 26 June 2020 12:54:46 +0800 (0:00:01.185) 0:00:01.325 *********** Friday 26 June 2020 12:54:47 +0800 (0:00:01.110) 0:00:02.435 *********** TASK [sleep 1] ************************************************************************************************************************************************************ changed: [192.168.122.10] changed: [192.168.122.11] changed: [192.168.122.12] Friday 26 June 2020 12:54:48 +0800 (0:00:01.104) 0:00:03.540 *********** Friday 26 June 2020 12:54:49 +0800 (0:00:01.103) 0:00:04.644 *********** Friday 26 June 2020 12:54:49 +0800 (0:00:00.118) 0:00:04.762 *********** changed: [192.168.122.13] TASK [success] ************************************************************************************************************************************************************ changed: [192.168.122.10] changed: [192.168.122.11] Friday 26 June 2020 12:54:49 +0800 (0:00:00.117) 0:00:04.879 *********** changed: [192.168.122.12] changed: [192.168.122.13] PLAY RECAP **************************************************************************************************************************************************************** 192.168.122.10 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.11 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.12 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.13 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 Friday 26 June 2020 12:54:49 +0800 (0:00:00.191) 0:00:05.071 *********** =============================================================================== sleep 1 ------------------------------------------------------------------------------------------------------------------------------------------------------------ 1.10s success ------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.19s host_pinned 模式下 PLAY [all] **************************************************************************************************************************************************************** Friday 26 June 2020 12:55:13 +0800 (0:00:00.128) 0:00:00.128 *********** TASK [sleep 1] ************************************************************************************************************************************************************ changed: [192.168.122.10] Friday 26 June 2020 12:55:14 +0800 (0:00:01.227) 0:00:01.356 *********** TASK [success] ************************************************************************************************************************************************************ changed: [192.168.122.10] Friday 26 June 2020 12:55:15 +0800 (0:00:00.131) 0:00:01.487 *********** TASK [sleep 1] ************************************************************************************************************************************************************ changed: [192.168.122.11] Friday 26 June 2020 12:55:16 +0800 (0:00:01.123) 0:00:02.610 *********** TASK [success] ************************************************************************************************************************************************************ changed: [192.168.122.11] Friday 26 June 2020 12:55:16 +0800 (0:00:00.124) 0:00:02.735 *********** TASK [sleep 1] ************************************************************************************************************************************************************ changed: [192.168.122.12] Friday 26 June 2020 12:55:17 +0800 (0:00:01.118) 0:00:03.853 *********** TASK [success] ************************************************************************************************************************************************************ changed: [192.168.122.12] Friday 26 June 2020 12:55:17 +0800 (0:00:00.124) 0:00:03.978 *********** TASK [sleep 1] ************************************************************************************************************************************************************ changed: [192.168.122.13] Friday 26 June 2020 12:55:18 +0800 (0:00:01.129) 0:00:05.108 *********** TASK [success] ************************************************************************************************************************************************************ changed: [192.168.122.13] PLAY RECAP **************************************************************************************************************************************************************** 192.168.122.10 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.11 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.12 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.122.13 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 Friday 26 June 2020 12:55:18 +0800 (0:00:00.126) 0:00:05.234 *********** =============================================================================== sleep 1 ------------------------------------------------------------------------------------------------------------------------------------------------------------ 1.13s success ------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.13s