Last active
June 13, 2018 03:38
-
-
Save naavveenn/e2011ed2d16162eb79afde84ba60b085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: local | |
connection: local | |
vars_files: | |
- /home/ansible/awscreds_ec2.yml #contain varible info as mentioned in comments | |
tasks: | |
- name: Get Instance ID | |
ec2_instance_facts: | |
aws_access_key: "{{ aws_id }}" | |
aws_secret_key: "{{ aws_key }}" | |
region: "{{ aws_region }}" | |
filters: | |
instance-state-name: running | |
register: ec2 | |
- name: Create a Basic CPU Alarm | |
ec2_metric_alarm: | |
aws_access_key: "{{ aws_id }}" | |
aws_secret_key: "{{ aws_key }}" | |
region: "{{ aws_region }}" | |
state: present | |
name: "msp-{{ type }}-{{ metric_name }}-{{ item.instance_id }}" | |
metric: "{{ metric_name }}" | |
namespace: "{{ namespace }}" | |
statistic: "{{ stats }}" | |
comparison: "{{ comparison }}" | |
threshold: "{{ threshold_value }}" | |
period: "{{ period }}" | |
evaluation_periods: 1 | |
unit: "{{ unit }}" | |
description: "High {{ metric_name }} for {{ item.instance_id }} - {{ type }}" | |
dimensions: {'InstanceId': "{{ item.instance_id }}"} | |
alarm_actions: "{{ sns_arn }}" | |
with_items: | |
- "{{ ec2.instances }}" | |
- name: Tagging | |
ec2_tag: | |
region: "{{ aws_region }}" | |
resource: "{{ item.instance_id }}" | |
state: present | |
tags: | |
Owner: Naveen | |
Distro: Ubuntu | |
with_items: | |
- "{{ ec2.instances }}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aws_id: XYZ
aws_key: XYZ
aws_region: us-east-2
type: warning
metric_name: "StatusCheckFailed"
namespace: "AWS/EC2"
stats: Average
comparison: ">="
threshold_value: 1
period: 300
unit: "Count"
sns_arn: ['arn:aws:sns:us-east-2:986373637382:Test']
##Metric: StatusCheckFailed
##Unit: Count
##Metric: CPUUtilization
##Unit: Percent
##Metric: MemoryUtilization
##Unit: Bytes
##namespace: System/Linux