【发布时间】:2015-06-29 21:25:10
【问题描述】:
我正在尝试找到一种方法来通过 ansible 并行触发多个 cloudformation api 调用。
随着堆栈的增长,单独触发每个任务会占用大量时间。我查看了将 poll 设置为 0 的 async 选项(即开即忘)。但这根本不会触发 cloudformation 任务。
有什么建议吗?
【问题讨论】:
标签: amazon-web-services ansible amazon-cloudformation
我正在尝试找到一种方法来通过 ansible 并行触发多个 cloudformation api 调用。
随着堆栈的增长,单独触发每个任务会占用大量时间。我查看了将 poll 设置为 0 的 async 选项(即开即忘)。但这根本不会触发 cloudformation 任务。
有什么建议吗?
【问题讨论】:
标签: amazon-web-services ansible amazon-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 playbook 中使用 shell 模块来触发它
【讨论】: