Skip to content

Commit

Permalink
Implement automatic zones
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Jul 25, 2017
1 parent 7ceb07b commit a42d046
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 0 deletions.
6 changes: 6 additions & 0 deletions icinga2-ansible-add-zones/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# defaults file for icinga2-ansible-add-zones

icinga2_zones_dir: "/etc/icinga2/zones.d/"
icinga_master_zone: "master"
icinga_merged_zones: '{{icinga_zones|combine({ icinga_master_zone : {} })}}'
12 changes: 12 additions & 0 deletions icinga2-ansible-add-zones/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# handlers file for icinga2-ansible-add-zones

- name: restart icinga2
service: name=icinga2
state=restarted
enabled=yes

- name: reload icinga2
service: name=icinga2
state=reloaded
enabled=yes
128 changes: 128 additions & 0 deletions icinga2-ansible-add-zones/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
galaxy_info:
author: your name
description:
company: your company (optional)
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 1.2
#
# Below are all platforms currently available. Just uncomment
# the ones that apply to your role. If you don't see your
# platform on this list, let us know and we'll get it added!
#
platforms:
- name: EL
versions:
# - all
# - 5
- 6
- 7
#- name: GenericUNIX
# versions:
# - all
# - any
- name: Fedora
versions:
# - all
# - 16
# - 17
# - 18
# - 19
- 20
- 21
- 22
- 23
- 24
#- name: opensuse
# versions:
# - all
# - 12.1
# - 12.2
# - 12.3
# - 13.1
# - 13.2
#- name: Amazon
# versions:
# - all
# - 2013.03
# - 2013.09
#- name: GenericBSD
# versions:
# - all
# - any
#- name: FreeBSD
# versions:
# - all
# - 8.0
# - 8.1
# - 8.2
# - 8.3
# - 8.4
# - 9.0
# - 9.1
# - 9.1
# - 9.2
#- name: Ubuntu
# versions:
# - all
# - lucid
# - maverick
# - natty
# - oneiric
# - precise
# - quantal
# - raring
# - saucy
# - trusty
#- name: SLES
# versions:
# - all
# - 10SP3
# - 10SP4
# - 11
# - 11SP1
# - 11SP2
# - 11SP3
#- name: GenericLinux
# versions:
# - all
# - any
#- name: Debian
# versions:
# - all
# - etch
# - lenny
# - squeeze
# - wheezy
#
# Below are all categories currently available. Just as with
# the platforms above, uncomment those that apply to your role.
#
#categories:
#- cloud
#- cloud:ec2
#- cloud:gce
#- cloud:rax
#- clustering
#- database
#- database:nosql
#- database:sql
#- development
#- monitoring
#- networking
#- packaging
#- system
#- web
dependencies: []
# List your role dependencies here, one per line. Only
# dependencies available via galaxy should be listed here.
# Be sure to remove the '[]' above if you add dependencies
# to this list.

29 changes: 29 additions & 0 deletions icinga2-ansible-add-zones/tasks/icinga2_add_zones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Copy Endpoint Zone Definitions
template: src=endpoint_zones.j2
dest={{ icinga2_zones_dir }}/{{ hostvars[item]['ansible_fqdn'] }}.conf
owner=icinga
group=icinga
mode=0640
with_items: "{{ groups['all'] }}"
notify:
- reload icinga2

- name: Copy Zone Definitions
template:
src: zone.j2
dest: "{{ icinga2_zones_dir }}/{{ item }}.conf"
owner: icinga
group: icinga
mode: 0640
with_items: "{{ icinga_merged_zones }}"
notify:
- reload icinga2

- name: Copy zones.conf
template:
src: zones.conf
dest: /etc/icinga2/zones.conf
owner: icinga
group: icinga
mode: 0640
11 changes: 11 additions & 0 deletions icinga2-ansible-add-zones/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# tasks file for icinga2-ansible-add-zones

- name: Ensure existance of {{ icinga2_zones_dir }}
file:
name: "{{ icinga2_zones_dir }}"
state: directory
owner: icinga
group: icinga

- include: icinga2_add_zones.yml
14 changes: 14 additions & 0 deletions icinga2-ansible-add-zones/templates/endpoint_zones.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object Endpoint "{{ hostvars[item]['ansible_fqdn'] }}" {
host = "{{ hostvars[item]['ansible_fqdn'] }}"
}

{% if 'icinga_zone' in hostvars[item] %}
object Zone "{{ hostvars[item]['ansible_fqdn'] }}" {
endpoints = [ "{{ hostvars[item]['ansible_fqdn'] }}" ]
{% if 'icinga_zone' in hostvars[item] %}
parent = "{{ hostvars[item]['icinga_zone'] }}"
{% else %}
parent = "{{ icinga_master_zone }}"
{% endif %}
}
{% endif %}
12 changes: 12 additions & 0 deletions icinga2-ansible-add-zones/templates/zone.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object Zone "{{ item }}" {
{% if 'parent' in icinga_merged_zones[item] %}
parent = "{{ icinga_merged_zones[item].parent }}"
{% endif %}

endpoints = [
{% for host, params in hostvars.iteritems() %}
{% if item == icinga_master_zone and 'icinga_zone' not in params %}
"{{ host }}",
{% endif %}{% endfor %}
]
}
1 change: 1 addition & 0 deletions icinga2-ansible-add-zones/templates/zones.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include_recursive "zones.d"

0 comments on commit a42d046

Please sign in to comment.