Ansible Playbook for Scout on Ubuntu

This is a sample Ansible task ( on how to setup Scout ( on Ubuntu. It needs to be included in an ansible playbook.

It’s a follow up to a previous blog describing an Ansible Playbook to setup an HAProxy system. This Ansible task can be included in the HAProxy playbook as well as any other playbooks with something like this:

PLAYBOOK: Install scout on Ubuntu
- name: scout
  hosts: all
  user: user-with-sudo
  sudo: True

    scout_key: YourScoutAPIKeyFromTheirWebsite

    - include: tasks/scout.yml

We start by defining a “task” file:

# TASK: ScoutApp Monitoring ( 

# Separate task to install Ruby
- include: ruby.yml

- name: Install scout + dependencies
  shell: >
    executable=/bin/bash source /etc/profile.d/;
    gem install scout scout_api --no-rdoc --no-ri

- name: Create scout home directory
  file: >
    dest=/root/.scout state=directory
    owner=root group=root mode=0700

In the same file add the crontab entry and logrotate entry for Scout.

- name: Scout cron script crontab
  template: >
    owner=root group=root mode=0444

- name: Scout cron script logrotate
  copy: >
    owner=root group=root mode=0444

This is what scout-crontab.j2 looks like:

# crontab for Scout monitoring run by root
* * * * * root /bin/bash -l -c 'scout -n "{{ ansible_fqdn }}" {{ scout_key }}' >> /var/log/scout.log 2>&1

And this is what scout-logrotate looks like:

      rotate 7

Now to install ruby using RVM, if you don’t want to use the system ruby (most of the times you don’t).

# TASK: Install Ruby on Ubuntu

- name: Install Ruby dependencies
  apt: pkg=$item state=latest install_recommends=no
    - autoconf
    - automake
    - bison
    - build-essential
    - curl
    - libc6-dev
    - libgdbm-dev
    - libffi-dev
    - libncurses5-dev
    - libreadline6
    - libreadline6-dev
    - libsqlite3-dev
    - libssl-dev
    - libtool
    - libyaml-dev
    - libxml2-dev
    - libxslt1-dev
    - openssl
    - pkg-config
    - sqlite3
    - subversion
    - zlib1g
    - zlib1g-dev

- name: Install RVM
  shell: curl -L | bash -s stable

- name: Install Ruby 2.0.0
  shell: >
    executable=/bin/bash source /etc/profile.d/;
    rvm install 2.0.0

- name: Set default ruby version
  shell: >
    executable=/bin/bash source /etc/profile.d/;
    rvm --default use 2.0.0

and now run it.

ansible-playbook -T 120 scout.yml

comments powered by Disqus