August 2, 2017 · ansible op5 nagios

How to use the Nagios module in Ansible to control op5

I recently discovered that Ansible has a Nagios module. It is pretty straight forward to use the module if you have a Nagios clone like op5.

The module gives us the option to point out a custom command file.

With the parameter cmdfile we can specify, and i'm quoting, "[The] path to the nagios command file (FIFO pipe). Only required if auto-detection fails.".

First let's take a look at where this command file is located in OP5.

First locate your nagios.cfg

locate nagios.cfg


Next up, find the location of the command file.

cat /opt/monitor/etc/nagios.cfg | grep command_file


That's it!

Now use the command_file path in your Ansible playbook.

- name: Schedule downtime
  hosts: nagios
    - nagios:
        author: Ansible
        action: downtime
        minutes: 30
        service: host
        host: dc01
        comment: Downtime scheduled by Ansible
        cmdfile: /opt/monitor/var/rw/nagios.cmd