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

Hey Andrew,

i just started with Ansible and I would like to install the Linux Icinga Agents with ansible too. As I’am still learning ansible i would like to see your approach. It is possible to share your ansible playbook fpr Agent configiuration?

Best regards,
Rafael

I have adding agents and satellites working using Ansible with separate files, this is the set of tasks for the hosts files:

And this does the same things for a separate zone file per node:

1 Like

Thanks for your examples. I will take a look into it.

As i havnt’ found a way, I just added the ability to add zones in this Ansible Role:

https://github.com/Icinga/ansible-icinga2

as i havent’ found a generic way to do so. I’am using this to deploy the Agents.
At the momnet this will overwrite the zonesfiles, but will create a backup before.
On the Master node I’am adding the zones via the ansible director module:

2 Likes