From 3df7239eefd971bbfb6d70630ef7a1d70ee80c0a Mon Sep 17 00:00:00 2001 From: Rottler Tamas Date: Sat, 10 Jun 2023 22:57:03 +0200 Subject: [PATCH] 1 --- handlers/main.yml | 6 ++++++ tasks/main.yml | 19 +++++++++++++++++++ templates/host | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 handlers/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/host diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..712ea1c --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: reload icinga2 + become: yes + service: name=icinga2 state=reloaded + +# vim: set tabstop=2 shiftwidth=2 expandtab smarttab: diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..951a751 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- name: "list previous host configs" + shell: ls -1 /etc/icinga2/conf.d/ansible_routeros/ | sed -e 's/\.[^\.]*$//' + register: previous_hosts + changed_when: false + +- name: "create conf file for each host" + template: src="host" dest="/etc/icinga2/conf.d/ansible_routeros/{{ item }}.conf" + with_items: "{{ hostlist }}" + notify: + - reload icinga2 + +- name: "remove stale hosts" + file: path="/etc/icinga2/conf.d/ansible_routeros/{{ item }}.conf" state=absent + with_items: "{{ previous_hosts.stdout_lines }}" + when: hostvars[item] is undefined + notify: + - reload icinga2 + diff --git a/templates/host b/templates/host new file mode 100644 index 0000000..be6f781 --- /dev/null +++ b/templates/host @@ -0,0 +1,47 @@ +# {{ ansible_managed }} + +{% set c = icinga_contact_default %} +{% if icinga_contact is defined %} +{% set c = icinga_contact %} +{% endif %} +object Host "{{ hostvars[item].inventory_hostname }}" { + import "generic-host" + address = "{{ hostvars[item].ansible_host }}" + vars.os = "routeros" + vars.notification["mail"] = { + groups = [ {{ c }} ] + } + icon_image = "routeros.png" + icon_image_alt = "MikroTik RouterOS" +} + +object Service "mikrotik" { + import "generic-service" + host_name = "{{ hostvars[item].inventory_hostname }}" + check_command = "mikrotik" + vars.snmpuser = "{{ hostvars[item].snmpuser }}" + vars.snmppasswd = "{{ hostvars[item].snmppasswd }}" +} + +{% if 'check_ltebackup' in hostvars[item].group_names %} +object Service "ltebackup" { + import "generic-service" + host_name = "{{ hostvars[item].inventory_hostname }}" + check_command = "mikrotik_ltebackup" + vars.user = "{{ hostvars[item].apiuser }}" + vars.password = "{{ hostvars[item].apipasswd }}" + vars.ca = "{{ hostvars[item].apica }}" +} +{% endif %} + +{% if hostvars[item].ov_backup_ip is defined %} +object Service "ping_ov_backup_ip" { + import "generic-service" + host_name = "{{ hostvars[item].inventory_hostname }}" + check_command = "ping" + vars.ping_address = "{{ hostvars[item].ov_backup_ip }}" +} +{% endif %} + + +# vim: set tabstop=4 shiftwidth=4 expandtab smarttab: