-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathprovision-elb-ec2-metric-alarm-playbook.yml
129 lines (122 loc) · 3.55 KB
/
provision-elb-ec2-metric-alarm-playbook.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
- hosts: localhost
connection: local
gather_facts: false
vars:
image: '{{ ami }}'
architecture: 'workshop-elb-ec2-metric-alarm'
loadb: '{{ architecture }}-lb'
auto_sc: '{{ architecture }}-asg'
lc: '{{ architecture }}-lc'
vars_files:
- amiKeys.yml
- regionInfo.yml
tasks:
- name: ELB
ec2_elb_lb:
scheme: internal
aws_access_key: '{{ ami_access }}'
aws_secret_key: '{{ ami_secret }}'
name: '{{ loadb }}'
region: '{{ regi }}'
health_check:
ping_protocol: http
ping_port: 8080
ping_path: '/health'
response_timeout: 5
interval: 60
unhealthy_threshold: 2
healthy_threshold: 2
subnets: '{{ subnetID }}'
security_group_ids: '{{ elb_security_group_ids }}'
state: '{{ state }}'
listeners:
- protocol: http
load_balancer_port: 80
instance_port: 8080
- name: Launch Configuration
tags:
- lc
ec2_lc:
aws_access_key: '{{ ami_access }}'
aws_secret_key: '{{ ami_secret }}'
region: '{{regi}}'
name: '{{lc}}'
image_id: '{{ image }}'
key_name: '{{ keypair }}'
security_groups: '{{ group }}'
instance_type: t2.micro
volumes:
- device_name: /dev/sda1
volume_size: 100
device_type: io1
iops: 3000
delete_on_termination: true
user_data: '{{ bootstrap_content }}'
state: '{{ state }}'
- name: Autoscaling Group
tags:
- asg
ec2_asg:
aws_access_key: '{{ ami_access }}'
aws_secret_key: '{{ ami_secret }}'
region: '{{ regi }}'
name: '{{ auto_sc }}'
load_balancers: '{{ loadb }}'
launch_config_name: '{{ lc }}'
min_size: 2
max_size: 4
desired_capacity: 2
vpc_zone_identifier: '{{ subnetID }}'
wait_for_instances: false
health_check_period: 300
health_check_type: ELB
tags: '{{ tags }}'
state: '{{ state }}'
- name: Scaling Policy
ec2_scaling_policy:
aws_access_key: '{{ ami_access }}'
aws_secret_key: '{{ ami_secret }}'
region: '{{ regi }}'
state: '{{ state }}'
name: '{{item.pol_name }}'
adjustment_type: 'ChangeInCapacity'
asg_name: '{{ auto_sc }}'
scaling_adjustment: '{{ item.changes }}'
min_adjustment_step: 1
cooldown: 300
register: policies
with_items:
- pol_name: 'cpuUP_{{ auto_sc }}_policy'
changes: +1
- pol_name: 'cpuDown_{{ auto_sc }}_policy'
changes: -1
- name: Metric Alarms
ec2_metric_alarm:
aws_access_key: '{{ ami_access }}'
aws_secret_key: '{{ ami_secret }}'
state: '{{ state }}'
region: '{{ regi }}'
name: '{{ item.names }}'
metric: 'CPUUtilization'
namespace: 'AWS/EC2'
statistic: Average
comparison: '{{item.compare}}'
threshold: '{{item.limits}}'
period: 60
evaluation_periods: 1
unit: 'Percent'
description: '{{ item.desc }}'
dimensions: {'AutoScalingGroupName':'{{ auto_sc }}'}
alarm_actions: '{{ item.pol }}'
with_items:
- names: 'cpuUP_{{ auto_sc }}'
compare: '>='
limits: '20.0'
desc: 'This will alarm when the average cpu usage of the ASG is greater than 20% for 1 minute'
pol: "{{ policies.results[0]['arn'] }}"
- names: 'cpuDown_{{ auto_sc }}'
compare: '<='
limits: '10.0'
desc: 'This will alarm when the average cpu usage of the ASG is less than 10% for 1 minute'
pol: "{{ policies.results[1]['arn'] }}"