如何在ansible中触发多个aws cloudformation任务?

时间:2015-06-29 12:34:49

标签: amazon-web-services ansible amazon-cloudformation

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

随着筹码的增长,每个任务分别引发了很多时间。我查看了异步选项,将poll设置为0(fire and forget)。但这根本不会触发云形成任务。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

解决方案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中的所有functuanality和triger单脚本封装起来 例如:

#!/bin/bash

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

然后在你的ansible playbook中使用shell模块来解决它