From 1a2e4e565d14e8a6a6436b704eaec67bb530ff03 Mon Sep 17 00:00:00 2001 From: Zolfa Date: Sun, 3 May 2020 18:39:27 +0200 Subject: [PATCH] roles/icinga2-monitoring: new monitored facts format --- roles/icinga2-monitoring/defaults/main.yaml | 4 +++- roles/icinga2-monitoring/tasks/main.yaml | 21 +++++++++++-------- .../icinga2-monitoring/templates/host.conf.j2 | 5 +++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/roles/icinga2-monitoring/defaults/main.yaml b/roles/icinga2-monitoring/defaults/main.yaml index 853de94..90c381e 100644 --- a/roles/icinga2-monitoring/defaults/main.yaml +++ b/roles/icinga2-monitoring/defaults/main.yaml @@ -1 +1,3 @@ -monitoring_host: [] +--- +monitoring_facts: {} +... diff --git a/roles/icinga2-monitoring/tasks/main.yaml b/roles/icinga2-monitoring/tasks/main.yaml index 712d65c..83b7ba4 100644 --- a/roles/icinga2-monitoring/tasks/main.yaml +++ b/roles/icinga2-monitoring/tasks/main.yaml @@ -1,15 +1,18 @@ - include_role: - name: service + name: 'service' vars: - service_name: icinga2 + service_name: 'icinga2' + tags: + - 'monitoring' - debug: - var: monitoring_host + var: 'monitoring_facts' -- name: add host monitoring +- name: 'MONITORING | configure HOST/{{ item.key }}' template: - src: host.conf.j2 - dest: "/etc/icinga2/conf.d/hosts/{{ item }}.conf" - with_items: - - "{{ monitoring_host }}" - notify: reload icinga2 + src: 'host.conf.j2' + dest: "/etc/icinga2/conf.d/hosts/{{ item.key }}.conf" + loop: '{{ monitoring_facts|dict2items }}' + notify: 'reload icinga2' + tags: + - 'monitoring' diff --git a/roles/icinga2-monitoring/templates/host.conf.j2 b/roles/icinga2-monitoring/templates/host.conf.j2 index 41f2144..8483a39 100644 --- a/roles/icinga2-monitoring/templates/host.conf.j2 +++ b/roles/icinga2-monitoring/templates/host.conf.j2 @@ -1,7 +1,8 @@ -object Host "{{ item }}" { +object Host "{{ item.key }}" { import "generic-host" + address = "{{ item.value.address }}" + vars.os = "Linux" - vars.address = "{{ hostvars | ip_from_inventory(item) }}" vars.sla = "24x7" }