[icinga-checkins] icinga.org: icinga2-ansible/master: Finally chosen monolithic template file

git at icinga.org git at icinga.org
Sat Jun 7 13:16:05 CEST 2014


Module: icinga2-ansible
Branch: master
Commit: 58bd3538073a3e2d8f3826cd7e6bbf6c1dea521e
URL:    https://git.icinga.org/?p=icinga2-ansible.git;a=commit;h=58bd3538073a3e2d8f3826cd7e6bbf6c1dea521e

Author: Valentino Gagliardi <valentino.g at servermanaged.it>
Date:   Mon Jun  2 00:03:16 2014 +0200

Finally chosen monolithic template file

---

 add_hosts.yml              |    2 +-
 inventory                  |   13 ++++++++++++-
 tasks/icinga2_add_host.yml |    3 +--
 templates/host_def.j2      |   27 ++++++++++++++++++++++-----
 4 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/add_hosts.yml b/add_hosts.yml
index a46c4b7..f624f2a 100644
--- a/add_hosts.yml
+++ b/add_hosts.yml
@@ -1,4 +1,4 @@
-- hosts: monitored
+- hosts: all
   gather_facts: yes
   sudo: yes
 
diff --git a/inventory b/inventory
index e03d563..d149ee8 100644
--- a/inventory
+++ b/inventory
@@ -2,6 +2,17 @@
 monitor_server1 ansible_ssh_host= ansible_ssh_user=
 monitor_server2 ansible_ssh_host= ansible_ssh_user=
 
-[monitored]
+[smtp_no]
+#Add here the hosts that will be checked only for ping4
+monitored_server1 ansible_ssh_host= ansible_ssh_user=
+monitored_server2 ansible_ssh_host= ansible_ssh_user=
+
+[smtp_only]
+#Add here the hosts that will be checked only for SMTP and ping4
+monitored_server1 ansible_ssh_host= ansible_ssh_user=
+monitored_server2 ansible_ssh_host= ansible_ssh_user=
+
+[http_only]
+#Add here the hosts that will be checked only for HTTP and ping4
 monitored_server1 ansible_ssh_host= ansible_ssh_user=
 monitored_server2 ansible_ssh_host= ansible_ssh_user=
diff --git a/tasks/icinga2_add_host.yml b/tasks/icinga2_add_host.yml
index 6efdc62..f984f2b 100644
--- a/tasks/icinga2_add_host.yml
+++ b/tasks/icinga2_add_host.yml
@@ -1,9 +1,8 @@
 - name: Copy Host Definitions
   template: src=host_def.j2 
-            dest={{ icinga2_hosts_dir }}{{ hostvars[item]['ansible_fqdn'] }}.conf
+            dest={{ icinga2_hosts_dir }}monitored_hosts.conf
             owner=root 
             group=root 
             mode=0644
-  with_items: groups['monitored']
   notify:
    - restart icinga2
diff --git a/templates/host_def.j2 b/templates/host_def.j2
index 09cfdae..6c3400f 100644
--- a/templates/host_def.j2
+++ b/templates/host_def.j2
@@ -1,9 +1,26 @@
-object Host "{{ hostvars[item]['ansible_fqdn'] }}" {
+{% for host in groups['smtp_no'] %}
+object Host "{{ hostvars[host]['ansible_fqdn'] }}" {
   import "generic-host"
-  address = "{{ hostvars[item]['ansible_eth0']['ipv4']['address'] }}"
-  vars.os = "Linux"
-  vars.sla = "24x7"
-  vars.http = "yes"
+  address = "{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}"
+  #This host will be monitored only for ping
+  vars.smtp = "no" 
+}
+{% endfor %}
+
+{% for host in groups['smtp_only'] %}
+object Host "{{ hostvars[host]['ansible_fqdn'] }}" {
+  import "generic-host"
+  address = "{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}"
+  #This host will be monitored only for smtp and ping
   vars.smtp = "yes"
 }
+{% endfor %}
 
+{% for host in groups['http_only'] %}
+object Host "{{ hostvars[host]['ansible_fqdn'] }}" {
+  import "generic-host"
+  address = "{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}"
+  #This host will be monitored only for http and ping
+  vars.http = "yes"
+}
+{% endfor %}



More information about the icinga-checkins mailing list