Skip to content

Instantly share code, notes, and snippets.

@suprememoocow
Created October 9, 2014 15:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save suprememoocow/8173862d88d6ce976c9d to your computer and use it in GitHub Desktop.
Save suprememoocow/8173862d88d6ce976c9d to your computer and use it in GitHub Desktop.
Use Ansible to Manage Cloudwatch Volume Alarms in AWS EC2
---
- action: ec2_facts
- name: "list volumes"
command: 'aws ec2 describe-volumes --filter Name=attachment.instance-id,Values={{ ansible_ec2_instance_id }}'
register: ec2_volumes_output
- set_fact:
ec2_volumes: "{{ ec2_volumes_output.stdout | from_json }}"
- set_fact:
ec2_volumes_list: "{{ ec2_volumes.Volumes }}"
- name: "managed_vol_queue_length_1"
ec2_metric_alarm:
state: present
region: "{{ ansible_ec2_placement_region }}"
name: "managed_{{ inventory_hostname }}_{{ item.VolumeId }}_vol_queue_len_1"
metric: "VolumeQueueLength"
namespace: "AWS/EBS"
statistic: Average
comparison: ">"
threshold: "{{ volume_queue_length_threshold_1 }}"
period: 60
evaluation_periods: 1
description: "{{ inventory_hostname }} volume {{ item.Attachments[0].Device }} queue length exceeds {{ volume_queue_length_threshold_1 }} for 1 minute. Managed by Ansible."
dimensions: { VolumeId: "{{ item.VolumeId }}" }
alarm_actions: "{{ cloudwatch_alarm_notify_arn }}"
ok_actions: "{{ cloudwatch_alarm_notify_arn }}"
aws_access_key: "{{aws_access_key_id}}"
aws_secret_key: "{{aws_secret_access_key}}"
with_items: ec2_volumes_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment