user3228188
user3228188

Reputation: 1731

How can i trigger multiple aws cloudformation tasks in ansible?

I am trying to find a way to trigger multiple cloudformation api calls via ansible in parallel.

As the stack has grown a lot triggering each task seperately is eating up a lot of time. I looked at async option with poll set to 0 ( fire and forget ). But this doesn't trigger the cloudformation task at all.

Any suggestions ?

Upvotes: 1

Views: 444

Answers (1)

Vor
Vor

Reputation: 35139

Solution 1: Wrap your cloudformation calls in ansible module (easy to create) and use threading module inside.

Example:

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()

Solution 2: Write a script that will encapsulate all the functuanality and triger single script in ansible Example:

#!/bin/bash

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

and then in your ansible playbook just use shell module to triger it

Upvotes: 1

Related Questions