-
Notifications
You must be signed in to change notification settings - Fork 19
/
provision_servers_engine.yml
78 lines (68 loc) · 2.23 KB
/
provision_servers_engine.yml
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
- name: Provision AWS Instances
hosts: localhost
gather_facts: no
vars_files:
- ./vars/default-vars.yml
tasks:
- name: Set Machine Type to Micro
set_fact:
machine_type: t2.micro
ec2_root_volume_name: /dev/xvda
when: instance_size == "micro"
- name: Set Machine Type to Small
set_fact:
machine_type: t3.small
ec2_root_volume_name: /dev/sda1
when: instance_size == "small"
- name: Set Machine Type to Medium
set_fact:
machine_type: t3.medium
ec2_root_volume_name: /dev/sda1
when: instance_size == "medium"
- name: Set Machine Type to large
set_fact:
machine_type: t3.large
ec2_root_volume_name: /dev/sda1
when: instance_size == "large"
- name: Create AWS SSH Key Pair
ec2_key:
name: "{{ ec2_prefix }}-key"
register: create_key
# This is just saving off the private key, this can only be done 1 time on the first creation of the key, pair
- name: Save Private Key Locally
copy:
content: "{{ create_key.key.private_key }}"
dest: "{{ working_dir }}/{{ ec2_prefix }}-key-private.pem"
mode: '0400'
when: create_key.changed
- name: Gather Subnet Information
ec2_vpc_subnet_info:
region: "{{ ec2_region }}"
filters:
"tag:application": "{{ application }}"
"tag:provisioner": "mford"
register: subnet_info
# - debug:
# var: subnet_info
- name: "Create EC2 instances for {{ application }}"
ec2:
assign_public_ip: true
key_name: "{{ ec2_prefix }}-key"
group: "{{ ec2_prefix }}-sg"
instance_type: "{{ machine_type }}"
image: "{{ ec2_image_id }}"
region: "{{ ec2_region }}"
count: "{{ num_instances }}"
wait: "{{ ec2_wait }}"
vpc_subnet_id: "{{ subnet_info.subnets[0].id }}"
instance_tags:
provisioner: mford
application: "{{ application }}"
Name: "{{ application }}"
demo: appdeployment
volumes:
- device_name: "{{ ec2_root_volume_name }}"
volume_type: gp2
volume_size: "{{ ec2_root_volume_size }}"
delete_on_termination: true