Skip to content

Instantly share code, notes, and snippets.

@developerinlondon
Forked from weirdbricks/memory-cloudwatch.yaml
Last active August 29, 2015 14:06
Show Gist options
  • Save developerinlondon/f0911c7d276671364759 to your computer and use it in GitHub Desktop.
Save developerinlondon/f0911c7d276671364759 to your computer and use it in GitHub Desktop.
- hosts: all
vars:
ec2_access_key: "AKIA-----------A"
ec2_secret_key: "i-------------/--------A"
remote_user: ec2-user
sudo: yes
tasks:
- name: "make sure package perl-switch is installed for the monitoring scripts"
yum: name=perl-Switch state=present
when: ansible_os_family == "RedHat"
- name: "make sure package perl-Sys-Syslog is installed for the monitoring scripts"
yum: name=perl-Sys-Syslog state=present
when: ansible_os_family == "RedHat"
- name: "make sure package perl-LWP-Protocol-https is installed for the monitoring scripts"
yum: name=perl-LWP-Protocol-https state=present
when: ansible_os_family == "RedHat"
- name: download scripts
get_url: url=http://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts-v1.1.0.zip dest=/tmp/CloudWatchMonitoringScripts.zip
- name: unzip the scripts
unarchive: src=/tmp/CloudWatchMonitoringScripts.zip dest=/tmp/
- name: delete archive
file: path=/tmp/CloudWatchMonitoringScripts.zip state=absent
- name: set Access key in credentials file
replace: dest=/tmp/aws-scripts-mon/awscreds.template regexp='AWSAccessKeyId=' replace='AWSAccessKeyId={{ ec2_access_key }}' backup=yes
- name: set Secret key in credentials file
replace: dest=/tmp/aws-scripts-mon/awscreds.template regexp='AWSSecretKey=' replace='AWSSecretKey={{ ec2_secret_key }}' backup=yes
- name: move directory out of /tmp
command: mv /tmp/aws-scripts-mon/ /root/ creates=/root/aws-scripts-mon/
- name: add command to cron
lineinfile: dest=/etc/crontab insertafter=EOF line="* * * * * root /root/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --aws-credential-file=/root/aws-scripts-mon/awscreds.template"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment