Ansible Playbook for upgrading Ubuntu based Nagios Server to latest version

Hello. This is a typical Ansible playbook code to upgrade your Nagios Server to the latest version (4.4.2, announced August 2018).
It has been tested with Ubuntu 16.04.4 LTS for the Nagios Server, OpenSuSE 42.3 and Ansible 2.6 for the Ansible server.
It is presumed that you have previously installed Nagios using source code, preferably with a 4.x version (upgrading from 3.x is different).
If you are new at this I suggest you go through the process manually at least once. Start here: https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/upgrading.html but be mindful because the process described there is too generic. Depending on what you needed to activate on your nagios server, you may need different options and additional steps.
If you are not new at this, you can take the playbook and modify it to suit your needs.
I am in no way responsible if you damage your system by applying commands that were not suited for it. Backup your system first, or take a snapshot if you are using Vmware as a platform (remember to remove it later if everything goes well, vmware snapshots are not equivalent to backup!).
You can replace nagiosserverhostname with yours, as it is declared in your ansible host files. Start here: https://docs.ansible.com/ansible/latest/index.html
You will need to know the basics of how to install Ansible, create a list of your servers and run the playbook.
I intend to polish my Full Nagios Core Installation guide (Core Server, Nagios Plugins, extra plugins, Nagios Graph etc) and publish it as well, and then create a Playbook for creating such an installation from scratch with Ansible. The last part is not ready yet. Perhaps I will get to update my notes for Ubuntu 18.04 LTS but as the season is picking up pace, I may have little time to spare for it. I will do my best.
I am sorry I can’t allow comments on this site, the spam is too much to handle. You can look me up on twitter and ask there.
There you go, I hope you find it usefull!
Don’t forget, it’s YAML syntax so indents are important plus other things you can read when you learn about Ansible.
Yannis.

---
- hosts: nagiosserverhostname
tasks:
- name: get rid of old installation dir
file:
path: /tmp/nagios
state: absent
- name: get rid of old installation archive
file:
path: /tmp/nagios.tar.gz
state: absent
- name: download and uncompress
shell: cd /tmp;rm nagios*.tar.gz;wget -O nagios.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.2.tar.gz;tar -zxf nagios.tar.gz;mv nagioscore-nagios-4.4.2 nagios
- name: change dir to /tmp
shell: cd /tmp/nagios;./configure --with-command-group=nagcmd --with-mail=/usr/sbin/sendmail --with-httpd-conf=/etc/apache2/;make all;make install;make install-init
- name: check configs syntax
shell: /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
- name: restart nagios service
service:
name: nagios
state: restarted
- name: get rid of old installation dir
file:
path: /tmp/nagios
state: absent
- name: get rid of old installation archive
file:
path: /tmp/nagios.tar.gz
state: absent