Created
June 15, 2014 22:22
-
-
Save weirdbricks/3e0d0e3428f3d683ccfa to your computer and use it in GitHub Desktop.
ansible playbook to add memory metrics for cloudwatch - RedHat family only
This file contains 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: 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
Thanks for the Script. I have faced some errors and I have tried to solve them using below script.
Note: Syntax of command may differ by version to version in Ansible Playbook.
vars:
ec2_access_key: "AKIA......................."
ec2_secret_key: "b..........................................................H"
remote_user: ec2-user
become: yes
tasks:
yum: name=perl-Switch state=present
when: ansible_distribution == "RedHat"
yum: name=perl-Sys-Syslog state=present
when: ansible_distribution == "RedHat"
yum: name=perl-LWP-Protocol-https state=present
when: ansible_distribution == "RedHat"
get_url: url=http://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts-v1.1.0.zip dest=/tmp/CloudWatchMonitoringScripts.zip
unarchive:
src: /tmp/CloudWatchMonitoringScripts.zip
dest: /tmp/
remote_src: True
file: path=/tmp/CloudWatchMonitoringScripts.zip state=absent
replace: dest=/tmp/aws-scripts-mon/awscreds.template regexp='AWSAccessKeyId=' replace='AWSAccessKeyId={{ ec2_access_key }}' backup=yes
replace: dest=/tmp/aws-scripts-mon/awscreds.template regexp='AWSSecretKey=' replace='AWSSecretKey={{ ec2_secret_key }}' backup=yes
command: mv /tmp/aws-scripts-mon/ /root/ creates=/root/aws-scripts-mon/
lineinfile: dest=/etc/crontab insertafter=EOF line="* * * * * root /root/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --disk-path=/dev/xvda2 --disk-space-util --disk-space-used --disk-space-avail --aws-credential-file=/root/aws-scripts-mon/awscreds.template"