ansible-并行运行剧本

ansible-并行运行剧本,ansible,Ansible,我有一本ansible的剧本,这本书是詹金斯一家每晚制作的。正如您所看到的,每一行都包含不同的产品组件。 有没有办法让它们并行运行?因此,服务器1的所有playbooks文件将以串行方式运行,但服务器1和服务器2的playbooks应以并行方式运行 - include: "componentA.yml target=server1" - include: "componentB.yml target=server1" - include: "componentC.yml target=serv

我有一本ansible的剧本,这本书是詹金斯一家每晚制作的。正如您所看到的,每一行都包含不同的产品组件。 有没有办法让它们并行运行?因此,服务器1的所有playbooks文件将以串行方式运行,但服务器1和服务器2的playbooks应以并行方式运行

- include: "componentA.yml target=server1"
- include: "componentB.yml target=server1"

- include: "componentC.yml target=server2"
- include: "componentD.yml target=server2"

您可以重构您的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。

我有很多服务器和组件,不想由Jenkins管理它。使用strategy:free选项,所以每次我都必须在循环中运行这个playbook来传递不同的服务器名?在一个playbook文件中没有其他方法来管理它,只是将“include”分组到块中并并行运行它们?恐怕没有。剧本应该分为多个剧本,每个剧本应该在一组服务器上完成相同的任务。例如,首先部署数据库服务器,然后部署应用程序服务器。感谢您的快速响应!管理这种情况的最佳做法是什么。我们有大约20个以不同方式部署的组件。所以我必须为每个组件保留playback.yml。如何在7台左右的服务器上管理所有这些软件的安装,其中有些是windows,有些是linux?现在,我只保留install_all.yml,它包含一个包含列表,就像我在上面的帖子中发布的一样。