From cd9750950587cb40b86a4ed9122b49b6ba155e7c Mon Sep 17 00:00:00 2001 From: Stephen Smoogen Date: Tue, 9 Jun 2020 11:19:01 -0400 Subject: [PATCH] make an iad2-internal hosts for our systems --- roles/nagios_server/tasks/main.yml | 12 +++++++ .../templates/nagios/hosts/iad2-hosts.cfg.j2 | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 roles/nagios_server/templates/nagios/hosts/iad2-hosts.cfg.j2 diff --git a/roles/nagios_server/tasks/main.yml b/roles/nagios_server/tasks/main.yml index 00cf94948f..8dd5267b0f 100644 --- a/roles/nagios_server/tasks/main.yml +++ b/roles/nagios_server/tasks/main.yml @@ -426,6 +426,18 @@ - nagios_hosts notify: restart nagios +## These are only available to the internal server +- name: Build out nagios host templates (production) + template: src=nagios/hosts/{{item}}.j2 dest=/etc/nagios/hosts/{{item}} mode=0644 owner=root group=root + with_items: + - iad2-hosts.cfg + when: env == "production" and nagios_location == 'iad2_internal' + tags: + - nagios_server + - nagios_config + - nagios_hosts + notify: restart nagios + - name: Build out nagios host templates (production) template: src=nagios/hosts/{{item}}.j2 dest=/etc/nagios/hosts/{{item}} mode=0644 owner=root group=root with_items: diff --git a/roles/nagios_server/templates/nagios/hosts/iad2-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/iad2-hosts.cfg.j2 new file mode 100644 index 0000000000..da3d6b8324 --- /dev/null +++ b/roles/nagios_server/templates/nagios/hosts/iad2-hosts.cfg.j2 @@ -0,0 +1,32 @@ +{% for host in groups['all']|sort %} +{% if hostvars[host].datacenter == 'iad2' and hostvars[host].nagios_Can_Connect == true %} +define host { +{% if hostvars[host].nagios_Check_Services['nrpe'] == true %} + use defaulttemplate +{% else %} + use mincheck +{% endif %} + host_name {{ host }} +{% if hostvars[host].ansible_hostname is defined %} + alias {{ hostvars[host].ansible_hostname }} +{% else %} + alias {{ host }} +{% endif %} +{% if hostvars[host].eth0_ip is defined %} + address {{ hostvars[host].eth0_ip }} +{% elif hostvars[host].ansible_default_ipv4 is defined %} +{% if hostvars[host].ansible_default_ipv4.address is defined %} + address {{ hostvars[host].ansible_default_ipv4.address }} +{% endif %} +{% else %} + address {{ host }} +{% endif %} +{% if hostvars[host]['vmhost'] is defined %} + parents {{ hostvars[host]['vmhost'] }} +{% elif hostvars[host].datacenter is defined %} + parents phx2-gw +{% endif %} +} + +{% endif %} +{% endfor %}