Start Cloudformation stacks in parallel from ansible

邮差的信 提交于 2019-12-11 04:08:13

问题


I am starting multiple cloudformation stacks in a "with_items" loop in ansible like this:

- 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 }}"

Can I somehow make ansible start this stacks in parallel?


回答1:


Using asynchronous tasks in a fire-and-forget scheme (and waiting for them to finish in a separate task) should work since 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


来源:https://stackoverflow.com/questions/42223344/start-cloudformation-stacks-in-parallel-from-ansible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!