Using Ansible to add Icinga2 agent to master node

I want to use Ansible to add Icinga2 passive monitoring for my hosts with agent monitoring. I have a single master node and am not using satellites yet.

I’ve had some success in setting up the client side thanks to this answer.

What commands do I need to run on the master node to add in the remote node?

I’m using Ansible so I specifically want to avoid the wizard.

I’ve looked at https://icinga.com/docs/icinga2/snapshot/doc/06-distributed-monitoring/#distributed-monitoring-master-agents and I can’t work out how to add extra hosts in one-by-one. It looks like the zones file on the master node at /etc/icinga2/zones needs to have all the hosts defined at once.

I’d prefer use separate files for each host that I’m managing because my Ansible skills aren’t good enough to be confident around inserting and deleting blocks of config within that file.

Are there any examples of Ansible setups like this?

Its fine to write the entrys for Endpoint, Zone and Host in one File per Host. File Location can be the Zone Directory:

/etc/icinga2/zones.d/master/agent1.conf

object Endpoint "icinga2-agent1.localdomain" {
  host = "192.168.56.111" // The master actively tries to connect to the agent
}

object Zone "icinga2-agent1.localdomain" {
  endpoints = [ "icinga2-agent1.localdomain" ]

  parent = "master"
}

object Host "icinga2-agent1.localdomain" {
  check_command = "hostalive"
  address = "192.168.56.111"

  vars.agent_endpoint = name //follows the convention that host name == endpoint name
}
3 Likes