Skip to content

Instantly share code, notes, and snippets.

@alonisser
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alonisser/23d3c9d0d5f7fb46840b to your computer and use it in GitHub Desktop.
Save alonisser/23d3c9d0d5f7fb46840b to your computer and use it in GitHub Desktop.
Ansible role for setting cloudwatch reporting script on ubuntu servers
[defaults]
hostfile = hosts
--roles
--aws_monitoring
--tasks
--main.yml
ansible.cfg
hosts
setup_aws_reporting.yml
[app_servers]
app1.example.com ansible_ssh_user=ubuntu
app2.example.com ansible_ssh_user=ubuntu
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
mkdir automation && cd automation
touch ansible.cfg && hosts
mkdir -pv roles/aws_monitoring/tasks/main.yml
- name: Updating apt-cache
sudo: yes
apt: update_cache=yes cache_valid_time=3600
- name: Installing perl pre requirements and unzip
sudo: yes
apt: pkg={{item}} state=installed
with_items:
- libwww-perl
- libdatetime-perl
- libswitch-perl
- unzip
- name: Checking if cloudwatch already Downloaded to this machine
stat: path=~/aws-scripts-mon
register: cloudwatch_folder
- name: Downloading aws cloudwatch reporting script
get_url: url=http://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts-v1.1.0.zip dest=~/CloudWatchMonitoringScripts-v1.1.0.zip
when: not cloudwatch_folder.stat.exists
- name: Unzipping cloudwatch
unarchive: src=/home/ubuntu/CloudWatchMonitoringScripts-v1.1.0.zip dest=/home/ubuntu/ copy=no
when: not cloudwatch_folder.stat.exists
- name: removing zip
file: path=/home/ubuntu/CloudWatchMonitoringScripts-v1.1.0 state=absent
- name: setup crontab reporting to aws cloud
cron: name="report aws" minute="1" job="~/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --disk-path=/ --disk-path=/home --disk-space-avail --disk-space-used --disk-space-util --aws-credential-file=/home/ubuntu/aws-scripts-mon/awscreds.template >/dev/null 2>&1"
---
- hosts: app_servers
remote_user: ubuntu
roles:
- role: aws_monitoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment