Skip to content

Commit

Permalink
Ansible:Nagios:Server - Automate Base Server Installation (#2638)
Browse files Browse the repository at this point in the history
* Nagios Server Installation

Playbook that installs nagios core on a new server. Either for new configuration to be implemented, or old configuration to be restored.

* Nagios Server Installation

Playbook that installs nagios core on a new server. Either for new configuration to be implemented, or old configuration to be restored.

* Documentation Ud

* Documentation Ud

* Document formatting updates

* Document formatting updates

* Remove Webhook Call.

* Remove Webhook Call.

* Fix Slack Webhook Configuration

* Fix Linter Error

* Fix Linter

* Linter fixes, reformat nagios inventory

* Remove errant vagrantfile

* Fix linter.

* Update Nagios Installation Tasks

* Update nagios_inventory.yml

* Update ansible/playbooks/nagios/README.md

Fix errant characters

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/README.md

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/README.md

Fix filename in doc

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Remove ubuntu check.

* Update ansible/playbooks/nagios/roles/Nagios_Server/tasks/install_nagiosgraph.yml

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/roles/Nagios_Server/tasks/install_nagiosgraph.yml

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/roles/Nagios_Server/tasks/install_nagiosgraph.yml

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Add default nagios admin user username

* Parameterise nagios admin user.

* Linter fixes

* Linter fixes

* Linter fix

* Linter fixes

* Linter fix

* Linter fix

* Linter fix

* Update ansible/playbooks/nagios/README.md

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/README.md

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/README.md

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/README.md

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/README.md

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

* Update ansible/playbooks/nagios/roles/Nagios_Server/tasks/main.yml

Co-authored-by: Wen Zhou <wenzhou@redhat.com>

Co-authored-by: Wen Zhou <wenzhou@redhat.com>
Co-authored-by: Martijn Verburg <martijnverburg@gmail.com>
  • Loading branch information
3 people authored Oct 6, 2022
1 parent 25f5186 commit 597ead2
Show file tree
Hide file tree
Showing 22 changed files with 1,231 additions and 57 deletions.
64 changes: 64 additions & 0 deletions ansible/playbooks/nagios/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
**IMPORTANT!**

Currently the Nagios server (4.4.7) installation playbook has only been developed and tested on Ubuntu 22.04. Changes will be required if you wish to install a Nagios Server on a different host OS

Ensure to update the ansible.cfg and nagios_inventory.yml files before running this playbook.

**Repository Contents:**

README.MD (This File)

1) ./VagrantFiles/

This directory contains a vagrantfile that can be used to create a test server for running the Nagios_Server playbook on.

**NB: For the Ubuntu 2204 Vagrantfile, its recommended to use a minimum Vagrant version of 2.2.19-1**

2) ./roles/*

This directory houses the ansible roles used in the creation of the nagios server.

3) ansible.cfg

This is the default configuration file for ansible

4) nagios_inventory.yml

This file is a simple ansible inventory file used for creating the nagios server, it only has a single entry which can be swapped in/out for running on a vagrant localhost

5) play_setup_server.yml

This is the playbook for installing the nagios server from scratch, it depends on the other 2 files (vars_setup_server.yml secrets_setup_server.enc) and contained within this directory

- vars_setup_server.yml - contains a list of variable defaults for a typical installation.
- secrets_setup_server.enc - is an ansible vault containing the default nagios admin password, and the slack webhook URL.

This was created by encrypting a plain text file, as per the example below :

ansible-vault encrypt secrets_setup_server.enc

The Encrypted File Contains 2 Sensitive Pieces Of Information.

nagios_admin_pass: xxxxxxxxxx
slack_webhook: xxxxxxxxxx

The Encrypted File Can Be Edited Using The Following Command (With The Relevant Password)

ansible-vault edit secrets_setup_server.enc

The Encrypted File Can Have Its Password Changed With The Following command

ansible-vault rekey secrets_setup_server.enc


**Usage Guide :**

1) Prior to running the nagios server installation playbook, ensure the ansible.cfg, nagios_inventory and the secrets_setup_server.enc vault file have been updated as necessary.

2) Either directly on the nagios server host (ansible must be installed), or alternatively from an ansible machine with connection to the nagios server to be.

ansible-playbook -b play_setup_server.yml --ask-vault-pass

Based off the [installation guide](https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html):
And Off This [GitRepo](https://github.com/Willsparker/AnsibleBoilerPlates/tree/main/Nagios) :
For some useful tips for working with vault files see [here](https://docs.ansible.com/ansible/latest/user_guide/vault.html)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

$script = <<SCRIPT
# Repair "==> default: stdin: is not a tty" message
sudo ex +"%s@DPkg@//DPkg" -cwq /etc/apt/apt.conf.d/70debconf
sudo dpkg-reconfigure debconf -f noninteractive -p critical
# Put the host machine's IP into the authorised_keys file on the VM
if [ -r /vagrant/id_rsa.pub ]; then
mkdir -p $HOME/.ssh && cat /vagrant/id_rsa.pub >> $HOME/.ssh/authorized_keys
fi
# Update OS
sudo apt-get update
sudo apt-get install ansible -y
# Repair "==> default: stdin: is not a tty" message
sudo ex +"%s@DPkg@//DPkg" -cwq /etc/apt/apt.conf.d/70debconf
sudo dpkg-reconfigure debconf -f noninteractive -p critical
sudo apt upgrade -y &>/dev/null
sudo shutdown -r now
SCRIPT

# 2 = version of configuration file for Vagrant 1.1+ leading up to 2.0.x
Vagrant.configure("2") do |config|

config.vm.define :nagios_server do |nagios_server|
nagios_server.vm.box = "generic/ubuntu2204"
nagios_server.vm.synced_folder ".", "/vagrant"
nagios_server.vm.hostname = "Nagios.Server"
nagios_server.vm.network :private_network, type: "dhcp"
nagios_server.vm.provision "shell", inline: $script, privileged: false
end

config.vm.provider "virtualbox" do |v|
v.gui = false
v.memory = 4096
v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
end
end
9 changes: 9 additions & 0 deletions ansible/playbooks/nagios/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[defaults]
become = no
become_method = sudo
inventory = ./nagios_inventory.yml
remote_user = ansible
private_key_file = ~/.ssh/id_rsa
# Vagrant Options Below
#remote_user = vagrant
#private_key_file = ./id_rsa
57 changes: 0 additions & 57 deletions ansible/playbooks/nagios/nagios_aix.yml.old

This file was deleted.

8 changes: 8 additions & 0 deletions ansible/playbooks/nagios/nagios_inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Put The localhost Entry (L7/L8) In Place For Vagrant Based Testing

Nagios_Server:
hosts:
#192.168.50.55
localhost:
ansible_connection: local
10 changes: 10 additions & 0 deletions ansible/playbooks/nagios/play_setup_server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Install Nagios
hosts: Nagios_Server
vars_files:
- secrets_setup_server.enc
- vars_setup_server.yml
tasks:
- name: Include Ansible installation role
include_role:
name: Nagios_Server
2 changes: 2 additions & 0 deletions ansible/playbooks/nagios/roles/Nagios_Server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This role installs and configures a nagios server from scratch on a new server.
Currently this role is only supported on Ubuntu 22.04.
31 changes: 31 additions & 0 deletions ansible/playbooks/nagios/roles/Nagios_Server/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# defaults file for Nagios_Installation
#
nagios_admin_user: nagiosadmin
nagios_admin_pass: password

nagios_version: 4.4.7
nagios_plugins_version: 2.3.3
pnp4nagios_plugin_version: 0.6.26
nagiosgraph_plugin_version: 1.5.2

make_list:
- all
- install-groups-users
- install
- install-daemoninit
- install-commandmode
- install-config
- install-webconf

extra_configure_args: ""

task_list:
- install_core
- install_plugins
- install_pnp4nagios
- install_nagiosgraph
- configure_nagios_core
- install_nagios_scripts
- configure_nagios_commands
- configure_nagios_server_monitoring
Loading

0 comments on commit 597ead2

Please sign in to comment.