-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathworkflow.yml
72 lines (62 loc) · 1.75 KB
/
workflow.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
---
- name: Create new EC2 instances
hosts: localhost
gather_facts: false
connection: local
vars:
region: us-east-1
ami: ami-81cf0c97
keypair: "{{ ec2_keypair_name | default('you need to define this') }}"
set_dns: False
count: 1
tags:
env: "{{ tags_env | default('prod') }}"
type: "{{ tags_type | default('app') }}"
wait_for_ssh: False
tasks:
- name: Launch instance
local_action:
module: ec2
keypair: "{{ keypair }}"
instance_type: "{{ type | default('t2.micro') }}"
vpc_subnet_id: "subnet-{{ vpc_subnet | default('d931e1e5') }}"
image: "{{ ami }}"
region: "{{ region }}"
count: "{{ count }}"
wait: yes
instance_tags: "{{ tags }}"
# user_data: "{{ lookup('file', '../scripts/ec2_bootstrap.sh') }}"
assign_public_ip: "{{ assign_eip | default(true) }}"
register: ec2
- name: Wait for SSH to come up
wait_for:
host: "{{ item.public_dns_name }}"
port: 22
delay: 60
timeout: 320
state: started
with_items: "{{ ec2.instances }}"
- name: Instance info
debug:
msg: "{{ item.id }} {{ item.public_ip }}"
with_items: "{{ ec2.instances }}"
- name: Deploy web application
hosts: tag_type_app
become: true
roles:
- { role: app }
- name: Register web app instance to ELB
hosts: tag_type_app
# become: true
tasks:
- name: Add host to ELB
local_action:
module: ec2_elb
ec2_region: us-east-1
instance_id: "{{ ec2_id }}" # instance_id from Ansible Facts
ec2_elbs: "{{ elb_name }}"
state: present
wait: yes
wait_timeout: 60
# become: false
ignore_errors: yes