繁体   English   中英

我如何在Ansible中触发多个AWS Cloudformation任务?

[英]How can i trigger multiple aws cloudformation tasks in ansible?

我正在尝试找到一种通过ansible并行触发多个cloudformation api调用的方法。

随着堆栈的增长,触发每个任务单独消耗大量时间。 我查看了将poll设置为0(即起即忘)的异步选项。 但这根本不会触发cloudformation任务。

有什么建议么 ?

解决方案1:将您的cloudformation调用包装在ansible模块(易于创建)中,并在其中使用线程模块。

例:

import threading

def main():

    module=AnsibleModule(
        argument_spec=dict(
            region=dict(choices=AWS_REGIONS, default='us-east-1'),
            aws_secret_key=dict(no_log=True),
            aws_access_key=dict(no_log=True)
            ...
        )
    )
    t = threading.Thread(target=cfn_command)
    threads.append(t)
    t.start()

解决方案2:编写一个脚本,将所有功能和触发单个脚本封装在ansible示例中:

#!/bin/bash

aws cloudformation list-stacks > foo &
aws cloudformation describe-stack --stack-name aaa > bar &

然后在您的ansible剧本中使用shell模块进行触发

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM