ansible - Walter-Stroebel/Nagios-CLI-Config GitHub Wiki
Using NagCliCfg as an Ansible module.
Included in this project are the files NagCliCfg.jar, nagclicfg.yml and nagclicfg.j2
The .yml file is a sample Role for installing NagCliCfg. It makes certain assumptions about where to put stuff, if you are wanting to use Ansible I suppose you will be able to make any needed adjustments for your environment.
- Create a roles/install_nagclicfg directory on your Ansible controller machine.
- NagCliCfg.jar goes in the sub-directory roles/install_nagclicfg/files
- nagclicfg.j2 goes in the sub-directory roles/install_nagclicfg/templates
- nagclicfg.yml goes in the sub-directory roles/install_nagclicfg/tasks renamed to main.yml
- Put the following mini-script in ansible/library/nagclicfg on your Ansible controller machine and make it executable. This is so Ansible will accept a "nagclicfg" action in a task.
#!/bin/bash
/root/bin/nagclicfg $*
Here is a sample run of changing the nagiosadmin email address.
Caveat: Whenever you have NagCliCfg write the nagios configuration, the result will be "changed".
Before:
cat /etc/nagios/nagclicfg.d/contact.cfg
define contact {
host_notification_commands notify-host-by-email
host_notification_options d,u,r,f,s
host_notification_period 24x7
name generic-contact
register 0
service_notification_commands notify-service-by-email
service_notification_options w,u,c,r,f,s
service_notification_period 24x7
}
define contact {
alias Nagios Admin
contact_name nagiosadmin
email [email protected]
use generic-contact
}
The ansible task to change the email address:
- nagclicfg: cmds="cd /contact/nagiosadmin^set email root@localhost^write^reload"
Running the task:
PLAY [someservers] ************************************************************
GATHERING FACTS ***************************************************************
ok: [some-server]
TASK: [ncc-examples | Change nagiosadmin email] *******************************
changed: [some-server]
PLAY RECAP ********************************************************************
some-server : ok=2 changed=1 unreachable=0 failed=0
And the result, already written and with Nagios reloaded:
cat /etc/nagios/nagclicfg.d/contact.cfg
define contact {
host_notification_commands notify-host-by-email
host_notification_options d,u,r,f,s
host_notification_period 24x7
name generic-contact
register 0
service_notification_commands notify-service-by-email
service_notification_options w,u,c,r,f,s
service_notification_period 24x7
}
define contact {
alias Nagios Admin
contact_name nagiosadmin
email root@localhost
use generic-contact
}