从 ansible 并行启动 Cloudformation 堆栈 [英] Start Cloudformation stacks in parallel from ansible

查看:28
本文介绍了从 ansible 并行启动 Cloudformation 堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在with_items"循环中以这样的 ansible 启动多个 cloudformation 堆栈:

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

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

Can I somehow make ansible start this stacks in parallel?

推荐答案

从 ansible 2.0 开始,在即发即忘的方案中使用异步任务(并等待它们在单独的任务中完成)应该可以工作:

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

这篇关于从 ansible 并行启动 Cloudformation 堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆