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

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

问题描述

我正在像这样的 with_items循环中启动多个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开始,-and-forget方案(并等待它们完成单独的任务)应该起作用:

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天全站免登陆