Installing Sensu plugins with Ansible

When I followed this document about installing Sensu plugins I noticed that plugins are installed in root’s .gem dir:

root@deepthought:~# find / -name check-disk-usage.rb
/root/.gem/ruby/2.0.0/gems/sensu-plugins-disk-checks-2.0.1/bin/check-disk-usage.rb
/root/.gem/ruby/2.0.0/bin/check-disk-usage.rb

This is due to default Ansible behaviour when installing gems. Documentation for gem module here states that by default user_install parameter is set to yes, however for Sensu plugins, this parameter  should be set to no.

Example code:

- name: Install sensu plugins
  gem: name={{ item }} state=present executable=/opt/sensu/embedded/bin/gem user_install=no
  with_items:
  - sensu-plugins-disk-checks
  - sensu-plugins-graphite

Plugins should be placed in proper location now:

root@deepthought:~# find / -name check-disk-usage.rb
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugins-disk-checks-2.0.1/bin/check-disk-usage.rb
/opt/sensu/embedded/bin/check-disk-usage.rb
root@deepthought:~# /opt/sensu/embedded/bin/ruby /root/.gem/ruby/2.0.0/gems/sensu-plugins-disk-checks-2.0.1/bin/check-disk-usage.rb -w 80 -c 90
CheckDisk OK: All disk usage under 80% and inode usage under 85%

Much better.

Posted in Ansible, Linux, Sysadmin | Leave a comment

Intalling GeoIP pip package on a Mac OSX

If you’re getting following error when installing GeoIP pip package:

$ pip install GeoIP
...
    py_GeoIP.c:23:10: fatal error: 'GeoIP.h' file not found
    #include "GeoIP.h"
             ^
    2 warnings and 1 error generated.
    error: command 'cc' failed with exit status 1

    ----------------------------------------
...

you can easily solve it by installing required libraries with brew:

$ brew install geoip
==> Downloading https://homebrew.bintray.com/bottles/geoip-1.6.9.el_capitan.bott
######################################################################## 100.0%
==> Pouring geoip-1.6.9.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/geoip/1.6.9: 16 files, 551.8K

You should be able to install GeoIP pip package now:

$ pip install GeoIP
Collecting GeoIP
  Using cached GeoIP-1.3.2.tar.gz
Building wheels for collected packages: GeoIP
  Running setup.py bdist_wheel for GeoIP ... done
  Stored in directory: /Users/krzywans/Library/Caches/pip/wheels/00/d5/bd/...
Successfully built GeoIP
Installing collected packages: GeoIP
Successfully installed GeoIP-1.3.2
Posted in All, Linux, Mac | Leave a comment

AWS OpsWorks Environment Variables interpolation

I’m working on a generic cookbook that can be used to deploy micro services via OpsWorks. One problem I ran into was related to Using Environment Variables.

Each app added to stack has own scope in Deployment Attributes. The problem I had was related to using same cookbook for multiple apps.

Here’s how You can access DB password from deploy attributes for app1:

password=<%= node[:deploy][:app1][:environment_variables][:dbpass] %>

if you want a generic cookbook this will not work as app1 is hardcoded. By adding app name to cookbook attributes or custom JSON in OpsWorks you can do something like this:

{
	"microservice": {
		"servicename": "foo"
	}
}

and you can use it in your template like this:

password=<%= node[:deploy][node[:microservice][:servicename]][:environment_variables][:dbpass] %>
Posted in All | Leave a comment