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 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:


object Endpoint "icinga2-agent1.localdomain" {
  host = "" // 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 = ""

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