我有一个ansible playbook,在每晚构建后从Jenkins调用。如您所见,每行都包含不同的产品组件。 有没有办法并行运行它们?所以到server1的所有playbooks文件都将以串行方式运行,但是server1和server2的playbooks应该并行运行。
- include: "componentA.yml target=server1"
- include: "componentB.yml target=server1"
- include: "componentC.yml target=server2"
- include: "componentD.yml target=server2"
答案 0 :(得分:0)
您可以重构您的Playbook以同时定位所有服务器,并将strategy: free
与动态包含的任务一起使用。像这样:
---
- hosts: server*
strategy: free
tasks:
- include: componentA_tasks.yml
when: inventory_hostname == 'server1'
- include: componentB_tasks.yml
when: inventory_hostname == 'server1'
- include: componentC_tasks.yml
when: inventory_hostname == 'server2'
- include: componentD_tasks.yml
when: inventory_hostname == 'server2'
这样,server2将不会等待server1上的每个任务完成,并将快进到componentC任务。
或者您可以将Jenkins管道拆分为并行任务,并在server1和server2的单独线程中执行ansible。