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" }