Skip to content

Instantly share code, notes, and snippets.

@naavveenn
Last active June 13, 2018 03:38
Show Gist options
  • Save naavveenn/c98504d6ba0e3259e18928baeeac68f1 to your computer and use it in GitHub Desktop.
Save naavveenn/c98504d6ba0e3259e18928baeeac68f1 to your computer and use it in GitHub Desktop.
---
#Creating memory alarm and make sure CLoudwatch role is assigned to the ec2 instances
- hosts: all #must have valid ips,ssh-keys and user-name.
become: yes
gather_facts: yes
tasks:
- name: Installing the required packages for Ubuntu Dist
apt:
name: "{{ item }}"
update_cache: yes
state: latest
with_items:
- unzip
- libwww-perl
- libdatetime-perl
when: ansible_os_family == "Debian"
- name: Installing the required packages for Redhat Dist
yum:
name: "{{ item }}"
state: latest
with_items:
- perl-Switch
- perl-Sys-Syslog
- perl-LWP-Protocol-https
- perl-DateTime
when: ansible_os_family == "RedHat"
- name: Download the script
get_url:
url: http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip
dest: /opt/CloudWatchMonitoringScripts.zip
- name: Unzip the script
shell: cd /opt && unzip /opt/CloudWatchMonitoringScripts.zip
register: output
- debug:
var: output
- name: Delete the Archive file
file:
path: /opt/CloudWatchMonitoringScripts.zip
state: absent
- name: Verfiy
shell: cd /opt/aws-scripts-mon && /opt/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --swap-util --swap-used --disk-space-util --disk-space-used --disk-space-avail --memory-units=megabytes --disk-space-units=gigabytes --disk-path=/dev/xvda1
register: script_out
- debug:
var: script_out
- name: Add it to crontab
lineinfile:
path: /etc/crontab
insertafter: EOF
line: "*/5 * * * * root /opt/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --swap-util --swap-used --disk-space-util --disk-space-used --disk-space-avail --memory-units=megabytes --disk-space-units=gigabytes --disk-path=/dev/xvda1"
register: cron_out
- debug:
var: cron_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment