从 ansible 并行启动 Cloudformation 堆栈

Start Cloudformation stacks in parallel from ansible

我在 ansible 中的 "with_items" 循环中启动多个 cloudformation 堆栈,如下所示:

- name: Create CF stack in AWS
  cloudformation:
    stack_name: "{{ item.name }}"
    state: "present"
    template: "{{ item.name }}.py.json"
    template_parameters: "{{ item.template_parameters }}"
  with_items: "{{ CF_TEMPLATE_ITEMS }}"

我能以某种方式让 ansible 并行启动这个堆栈吗?

在 fire-and-forget 方案中使用异步任务(并等待它们在单独的任务中完成)自 ansible 2.0 起应该可以工作:

- name: Create CF stack in AWS
  async: 100
  poll: 0
  cloudformation:
    stack_name: "{{ item.name }}"
    state: "present"
    template: "{{ item.name }}.py.json"
    template_parameters: "{{ item.template_parameters }}"
  with_items: "{{ CF_TEMPLATE_ITEMS }}"
  register: cf_stack_async_results

- async_status:
    jid: "{{item.ansible_job_id}}"
  with_items: cf_stack_async_results.results
  register: cf_stack_async_poll_results
  until: cf_stack_async_poll_results.finished
  retries: 30