You need to sign in or sign up before continuing.
cloudformation.yml 1.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
---
# This playbook demonstrates how to use the ansible cloudformation module to launch an AWS CloudFormation stack.
#
# This module requires that the boto python library is installed, and that you have your AWS credentials
# in $HOME/.boto

#The thought here is to bring up a bare infrastructure with CloudFormation, but use ansible to configure it.
#I generally do this in 2 different playbook runs as to allow the ec2.py inventory to be updated.

#This module also uses "complex arguments" which were introduced in ansible 1.1 allowing you to specify the
#Cloudformation template parameters

#This example launches a 3 node AutoScale group, with a security group, and an InstanceProfile with root permissions.

#If a stack does not exist, it will be created.  If it does exist and the template file has changed, the stack will be updated.
#If the parameters are different, the stack will also be updated.

#CloudFormation stacks can take awhile to provision, if you are curious about its status, use the AWS
#web console or one of the CloudFormation CLI's.

#Example update -- try first launching the stack with 3 as the ClusterSize.  After it is launched, change it to 4
#and run the playbook again.

- name: provision stack
  hosts: localhost
  connection: local
  gather_facts: false

  # Launch the cloudformation-example.json template.  Register the output.

  tasks:
  - name: edX configuration
    cloudformation: >
34 35
      stack_name="{{ name }}" state=present
      region="{{ region }}" disable_rollback=false
36 37 38
      template=../cloudformation_templates/edx-server-multi-instance.json
    args:
      template_parameters:
39
        KeyName: "{{key}}"
40
        InstanceType: m1.small
41
        GroupTag: "{{group}}"
42 43
    register: stack
  - name: show stack outputs
44
    debug: msg="My stack outputs are {{stack.stack_outputs}}"