edx_provision.yml 2.69 KB
Newer Older
1
- name: Create ec2 instance
2 3
  hosts: localhost
  connection: local
4
  gather_facts: True
5 6
  vars:
    keypair: continuous-integration
7 8
    instance_type: t2.medium
    security_group: sandbox-vpc
9 10
    # ubuntu 16.04 - 20170721
    ami: ami-cd0f5cb6
11
    region: us-east-1
12
    zone: us-east-1c
13 14 15 16 17 18 19 20
    instance_tags:
      environment: sandbox
      github_username: temp
      Name: sandbox-temp
      source: provisioning-script
      owner: temp
    root_ebs_size: 50
    dns_name: temp
21
    dns_zone: sandbox.edx.org
22 23
    name_tag: sandbox-temp
    elb: false
24
    ec2_vpc_subnet_id: subnet-cd867aba
25 26 27 28 29 30 31
    instance_userdata: |
      #!/bin/bash
      set -x
      set -e
      export RUN_ANSIBLE=false;
      wget https://raw.githubusercontent.com/edx/configuration/{{ configuration_version }}/util/install/ansible-bootstrap.sh -O - | bash;
    launch_wait_time: 5
32
  roles:
John Jarvis committed
33
    - role: launch_ec2
John Jarvis committed
34 35 36
      keypair: "{{ keypair }}"
      instance_type: "{{ instance_type }}"
      security_group: "{{ security_group }}"
37
      ami: "{{ ami }}"
John Jarvis committed
38 39
      region: "{{ region }}"
      instance_tags: "{{ instance_tags }}"
John Jarvis committed
40
      root_ebs_size: "{{ root_ebs_size }}"
41
      dns_name: "{{ dns_name }}"
42
      dns_zone: "{{ dns_zone }}"
43
      zone: "{{ zone }}"
44
      vpc_subnet_id: "{{ ec2_vpc_subnet_id }}"
45
      assign_public_ip: yes
46
      terminate_instance: true
47
      instance_profile_name: sandbox
48 49
      user_data: "{{ instance_userdata }}"
      launch_ec2_wait_time: "{{ launch_wait_time }}"
50 51 52

- name: Configure instance(s)
  hosts: launched
53
  become: True
54
  gather_facts: False
55
  vars:
56
    elb: False
57 58
  pre_tasks:
    - name: Wait for cloud-init to finish
59 60
      wait_for:
        path: /var/log/cloud-init.log
61
        timeout: 15 
62
        search_regex: "final-message"
63 64
    - name: gather_facts
      setup: ""
65 66 67 68
  vars_files:
    - roles/edxapp/defaults/main.yml
    - roles/xqueue/defaults/main.yml
    - roles/xserver/defaults/main.yml
69
    - roles/forum/defaults/main.yml
70
  roles:
71
    # rerun common to set the hostname, nginx to set basic auth
72
    - common
73
    - aws
74
    - edx-sandbox
75 76 77 78 79 80
    - role: nginx
      nginx_sites:
      - cms
      - lms
      - xqueue
      - xserver
e0d committed
81
      - forum
82 83
      nginx_default_sites:
      - lms
84
  post_tasks:
85 86 87 88 89
    - name: get instance id for elb registration
      local_action:
        module: ec2_lookup
        region: us-east-1
        tags:
90
          - Name: "{{ name_tag }}"
91 92
      register: ec2_info
      when: elb
93
      become: False
94 95
    - name: register instance into an elb if one was provided
      local_action:
96
        module: ec2_elb
97
        region: "{{ region }}"
98
        instance_id: "{{ ec2_info.instance_ids[0] }}"
John Jarvis committed
99
        state: present
100 101 102
        ec2_elbs:
          - "{{ elb }}"
      when: elb
103
      become: False