Commit 0b929275 by Feanil Patel

Use python to create the stack. And setup DNS.

parent 05bc61a4
# Create a cloudformation stack.
- name: Create cloudformation stack for {{STACK_NAME}}
hosts: localhost
connection: local
gather_facts: False
roles:
- launch_cfn
# Provision Users on everything.
- name: Create Users
hosts: tag_aws_cloudformation_stack-name_{{STACK_NAME}}
roles:
- gh_users
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
##
# Defaults for role launch_cfn
#
#
# vars are namespace with the module name.
#
launch_cfn_role_name: launch_cfn
#
# OS packages
#
launch_cfn_debian_pkgs: []
launch_cfn_redhat_pkgs: []
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Handlers for role launch_cfn
#
# Overview:
#
#
- name: launch_cfn | notify me
debug: msg="stub handler"
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
##
# Role includes for role launch_cfn
#
# Example:
#
# dependencies:
# - {
# role: my_role
# my_role_var0: "foo"
# my_role_var1: "bar"
# }
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role launch_cfn
#
# Overview:
# Create a cloudformation stack.
#
#
# Dependencies:
#
#
# Example play:
#
#
- name: Create the stack.
cloudformation: >
stack_name="{{CFN_NAME}}"
region="{{CFN_REGION}}"
template="/Users/feanil/src/configuration/cloudformation_templates/edx-reference-architecture.json"
args:
template_parameters:
KeyName: 'continuous-integration'
import boto
import time
region = 'us-east-1'
stack_name = 'testautostack'
template = '/Users/feanil/src/configuration/cloudformation_templates/edx-reference-architecture.json'
def create_stack(stack_name,region='us-east-1',template_file):
cfn = boto.connect_cloudformation()
stack_id = cfn.create_stack(stack_name,
stack_body=open(template).read(),
capabilities=['CAPABILITIY_IAM'],
notification_arns=['arn:aws:sns:us-east-1:372153017832:stack-creation-events'],
tags={'autostack':'true'})
while True:
sleep(1)
stack_instance = cfn.describe_stacks(stack_id)[0]
status = stack_instance.stack_status
if 'COMPLETE' in status:
break
else:
print(status)
create_stack(stack_name, region, template)
print('Stack({}) created.'.format(stack_name))
# Create DNS for edxapp and xqueue.
dns_settings = {
'edxapp' : [ 'courses', 'studio' ],
'xqueue' : [ 'xqueue' ],
'rabbit' : [ 'rabbit' ],
'xserver' : [ 'xserver' ],
'worker' : [ 'worker' ],
}
# Create a zone for the stack.
zone_name = "{}.vpc.edx.org".format(stack_name)
#TODO Make this a function instead of a class method.
zone = get_or_create_hosted_zone(zone_name)
elbs = boto.connect_elb()
#TODO Implement this.
stack_elbs = elbs_for_stack_name(stack_name)
for elb in stack_elbs:
for service, dns_prefixes in dns_settings.items():
if service in elb.dns_name.lower():
for prefix in dns_prefixes:
# TODO: Make this function.
create_service_dns(elb, prefix, zone_name)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment