Category Archives: Ansible

Nagios NRPE Ansible Playbook

Previously we have installed nrpe checks and additional utils with bash script. Let’s install same configuration with simple Ansible:

Advantages of a deployment tool such as Ansible over bash script:
– We can run Ansible playbook many times and result will be the same as we desired (Idempotence)
– We can run Ansible playbook on multiple Nodes with one command

[root@ansible nagios]# tree
.
├── aw.awk
├── check_raid
├── check_raid.pl
├── check_smart
├── check_smart.pl
├── nagios.yaml
└── nrpe.cfg

---
- hosts: All
  remote_user: root

  tasks:
  - name: install epel
    yum:
      name: epel-release
      state: present

  - name: install nrpe
    yum:
      name: nrpe
      state: present

  - name: install nagios plugins & utils
    yum:
      name: [ 'nagios-plugins', 'nagios-common', 'nagios-plugins-load', 'nagios-plugins-uptime', 'smartmontools' ]
      state: present

  - name: install MegaCli
    yum:
      name: http://mirror.cogentco.com/pub/misc/MegaCli-8.07.14-1.noarch.rpm
      state: present

  - name: Symlink MegaCli
    file:
     src: /opt/MegaRAID/MegaCli/MegaCli64
     dest: /usr/bin/MegaCli
     owner: root
     group: root
     state: link

  - name: deploy check_raid.pl
    copy:
      src: /etc/ansible/playbook/nagios/check_raid.pl
      dest: /usr/lib64/nagios/plugins/check_raid.pl
      owner: root
      group: root
      mode: 0755

  - name: deploy aw.awk
    copy:
      src: /etc/ansible/playbook/nagios/aw.awk
      dest: /usr/lib64/nagios/plugins/aw.awk
      owner: root
      group: root
      mode: 0644

  - name: deploy sudoers check_raid
    copy:
      src: /etc/ansible/playbook/nagios/check_raid
      dest: /etc/sudoers.d/check_raid
      owner: root
      group: root
      mode: 0440

  - name: deploy check_smart.pl
    copy:
      src: /etc/ansible/playbook/nagios/check_smart.pl
      dest: /usr/lib64/nagios/plugins/check_smart.pl
      owner: root
      group: root
      mode: 0755

  - name: deploy sudoers check_smart
    copy:
      src: /etc/ansible/playbook/nagios/check_smart
      dest: /etc/sudoers.d/check_smart
      owner: root
      group: root
      mode: 0440

  - name: deploy nrpe.cfg
    copy:
      src: /etc/ansible/playbook/nagios/nrpe.cfg
      dest: /etc/nagios/nrpe.cfg
    register: deploy_nrpe

  handlers:
  - name: restart nrpe
    service:
      name: nrpe
      state: restarted

[root@ansible nagios]# ansible-lint nagios.yaml
[root@ansible nagios]# ansible-playbook nagios.yaml