I'm learning Ansible and I would like to install Nagios server with several monitored nodes. Nagios install steps that I'm following are from this tutorial on Digitalocean.
Step 5 of this tutorial confuses me as this is my first time using Ansible. This step involves a configuration file for monitored node on the master server, which I achieved using templates like this
- name: Configure Nagios server
hosts: master
sudo: true
vars:
nagios_slaves_config_dir: /etc/nagios/servers
nagios_config_file: /etc/nagios/nagios.cfg
tasks:
# shortened for brevity
- name: copy slaves config
template: src=../templates/guest.cfg.j2 dest=/etc/nagios/servers/{{ item }}.cfg owner=root mode=0644
with_items: groups['slaves']
Template looks like this
define host {
use linux-server
host_name {{ inventory_hostname }}
alias {{ inventory_hostname }}
address {{ hostvars['slave'].ansible_eth1.ipv4.address }}
}
define service {
use generic-service
host_name {{ inventory_hostname }}
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
This configuration file gets created but {{ inventory_hostname }}
variable is wrong - instead of node_1
it states master
How can I template the configuration file for every monitored node so that it is created with the proper values?
:EDIT:
One idea is to generate config files on monitored nodes and copy them to master node. Will try tomorrow.