switch to hosts based approach
This commit is contained in:
parent
133174dc41
commit
f95a41094a
@ -1,6 +1,10 @@
|
|||||||
---
|
---
|
||||||
- name: reload icinga2
|
- name: reload icinga2
|
||||||
become: yes
|
become: yes
|
||||||
service: name=icinga2 state=reloaded
|
systemd_service:
|
||||||
|
name: icinga2
|
||||||
|
state: reloaded
|
||||||
|
delegate_to: localhost
|
||||||
|
run_once: yes
|
||||||
|
|
||||||
# vim: set tabstop=2 shiftwidth=2 expandtab smarttab:
|
# vim: set tabstop=2 shiftwidth=2 expandtab smarttab:
|
||||||
|
|||||||
@ -2,18 +2,26 @@
|
|||||||
- name: "list previous host configs"
|
- name: "list previous host configs"
|
||||||
shell: ls -1 /etc/icinga2/conf.d/ansible_routeros/ | sed -e 's/\.[^\.]*$//'
|
shell: ls -1 /etc/icinga2/conf.d/ansible_routeros/ | sed -e 's/\.[^\.]*$//'
|
||||||
register: previous_hosts
|
register: previous_hosts
|
||||||
|
delegate_to: localhost
|
||||||
|
run_once: true
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: "create conf file for each host"
|
- name: "create conf file for host"
|
||||||
template: src="host" dest="/etc/icinga2/conf.d/ansible_routeros/{{ item }}.conf"
|
template:
|
||||||
with_items: "{{ hostlist }}"
|
src: "host"
|
||||||
|
dest: "/etc/icinga2/conf.d/ansible_routeros/{{ inventory_hostname }}.conf"
|
||||||
notify:
|
notify:
|
||||||
- reload icinga2
|
- reload icinga2
|
||||||
|
|
||||||
- name: "remove stale hosts"
|
- name: "remove stale hosts"
|
||||||
file: path="/etc/icinga2/conf.d/ansible_routeros/{{ item }}.conf" state=absent
|
file:
|
||||||
|
path: "/etc/icinga2/conf.d/ansible_routeros/{{ item }}.conf"
|
||||||
|
state: absent
|
||||||
with_items: "{{ previous_hosts.stdout_lines }}"
|
with_items: "{{ previous_hosts.stdout_lines }}"
|
||||||
when: hostvars[item] is undefined
|
when: "hostvars[item] is undefined"
|
||||||
|
delegate_to: localhost
|
||||||
|
run_once: true
|
||||||
notify:
|
notify:
|
||||||
- reload icinga2
|
- reload icinga2
|
||||||
|
|
||||||
|
# vim: set tabstop=2 shiftwidth=2 expandtab smarttab:
|
||||||
|
|||||||
@ -4,9 +4,9 @@
|
|||||||
{% if icinga_contact is defined %}
|
{% if icinga_contact is defined %}
|
||||||
{% set c = icinga_contact %}
|
{% set c = icinga_contact %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
object Host "{{ hostvars[item].inventory_hostname }}" {
|
object Host "{{ inventory_hostname }}" {
|
||||||
import "generic-host"
|
import "generic-host"
|
||||||
address = "{{ hostvars[item].ansible_host }}"
|
address = "{{ ansible_host }}"
|
||||||
vars.os = "routeros"
|
vars.os = "routeros"
|
||||||
vars.notification["mail"] = {
|
vars.notification["mail"] = {
|
||||||
groups = [ {{ c }} ]
|
groups = [ {{ c }} ]
|
||||||
@ -17,56 +17,56 @@ object Host "{{ hostvars[item].inventory_hostname }}" {
|
|||||||
|
|
||||||
object Service "ssh" {
|
object Service "ssh" {
|
||||||
import "generic-service"
|
import "generic-service"
|
||||||
host_name = "{{ hostvars[item].inventory_hostname }}"
|
host_name = "{{ inventory_hostname }}"
|
||||||
check_command = "ssh"
|
check_command = "ssh"
|
||||||
{% if hostvars[item].ansible_port is defined %}
|
{% if ansible_port is defined and ansible_port != 22 %}
|
||||||
vars.ssh_port = "{{ hostvars[item].ansible_port }}"
|
vars.ssh_port = "{{ ansible_port }}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
object Service "mikrotik" {
|
object Service "mikrotik_system" {
|
||||||
import "generic-service"
|
import "generic-service"
|
||||||
host_name = "{{ hostvars[item].inventory_hostname }}"
|
host_name = "{{ inventory_hostname }}"
|
||||||
check_command = "mikrotik"
|
check_command = "mikrotik_system"
|
||||||
vars.snmpuser = "{{ hostvars[item].snmpuser }}"
|
vars.apiuser = "{{ apiuser }}"
|
||||||
vars.snmppasswd = "{{ hostvars[item].snmppasswd }}"
|
vars.apipasswd = "{{ apipasswd }}"
|
||||||
}
|
}
|
||||||
|
|
||||||
{% if 'check_ltebackup' in hostvars[item].group_names %}
|
{% if 'check_ltebackup' in group_names %}
|
||||||
object Service "ltebackup" {
|
object Service "ltebackup" {
|
||||||
import "generic-service"
|
import "generic-service"
|
||||||
host_name = "{{ hostvars[item].inventory_hostname }}"
|
host_name = "{{ inventory_hostname }}"
|
||||||
check_command = "mikrotik_ltebackup"
|
check_command = "mikrotik_ltebackup"
|
||||||
vars.user = "{{ hostvars[item].apiuser }}"
|
vars.user = "{{ apiuser }}"
|
||||||
vars.password = "{{ hostvars[item].apipasswd }}"
|
vars.password = "{{ apipasswd }}"
|
||||||
vars.ca = "{{ hostvars[item].apica }}"
|
vars.ca = "{{ apica }}"
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if hostvars[item].ov_backup_ip is defined %}
|
{% if ov_backup_ip is defined %}
|
||||||
object Service "ping_ov_backup_ip" {
|
object Service "ping_ov_backup_ip" {
|
||||||
import "generic-service"
|
import "generic-service"
|
||||||
host_name = "{{ hostvars[item].inventory_hostname }}"
|
host_name = "{{ inventory_hostname }}"
|
||||||
check_command = "ping"
|
check_command = "ping"
|
||||||
vars.ping_address = "{{ hostvars[item].ov_backup_ip }}"
|
vars.ping_address = "{{ ov_backup_ip }}"
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if hostvars[item].extra_ping is defined %}
|
{% if extra_ping is defined %}
|
||||||
object Service "ping_{{ hostvars[item].extra_ping }}" {
|
object Service "ping_{{ extra_ping }}" {
|
||||||
import "generic-service"
|
import "generic-service"
|
||||||
host_name = "{{ hostvars[item].inventory_hostname }}"
|
host_name = "{{ inventory_hostname }}"
|
||||||
check_command = "ping"
|
check_command = "ping"
|
||||||
vars.ping_address = "{{ hostvars[item].extra_ping }}"
|
vars.ping_address = "{{ extra_ping }}"
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if hostvars[item].extra_ssh is defined %}
|
{% if extra_ssh is defined %}
|
||||||
object Service "ssh_{{ hostvars[item].extra_ssh }}" {
|
object Service "ssh_{{ extra_ssh }}" {
|
||||||
import "generic-service"
|
import "generic-service"
|
||||||
host_name = "{{ hostvars[item].inventory_hostname }}"
|
host_name = "{{ inventory_hostname }}"
|
||||||
check_command = "ssh"
|
check_command = "ssh"
|
||||||
vars.ssh_address = "{{ hostvars[item].extra_ssh }}"
|
vars.ssh_address = "{{ extra_ssh }}"
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user