Skip to content

Commit a42d046

Browse files
committed
Implement automatic zones
1 parent 7ceb07b commit a42d046

File tree

8 files changed

+213
-0
lines changed

8 files changed

+213
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
# defaults file for icinga2-ansible-add-zones
3+
4+
icinga2_zones_dir: "/etc/icinga2/zones.d/"
5+
icinga_master_zone: "master"
6+
icinga_merged_zones: '{{icinga_zones|combine({ icinga_master_zone : {} })}}'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
# handlers file for icinga2-ansible-add-zones
3+
4+
- name: restart icinga2
5+
service: name=icinga2
6+
state=restarted
7+
enabled=yes
8+
9+
- name: reload icinga2
10+
service: name=icinga2
11+
state=reloaded
12+
enabled=yes
+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
galaxy_info:
3+
author: your name
4+
description:
5+
company: your company (optional)
6+
# Some suggested licenses:
7+
# - BSD (default)
8+
# - MIT
9+
# - GPLv2
10+
# - GPLv3
11+
# - Apache
12+
# - CC-BY
13+
license: license (GPLv2, CC-BY, etc)
14+
min_ansible_version: 1.2
15+
#
16+
# Below are all platforms currently available. Just uncomment
17+
# the ones that apply to your role. If you don't see your
18+
# platform on this list, let us know and we'll get it added!
19+
#
20+
platforms:
21+
- name: EL
22+
versions:
23+
# - all
24+
# - 5
25+
- 6
26+
- 7
27+
#- name: GenericUNIX
28+
# versions:
29+
# - all
30+
# - any
31+
- name: Fedora
32+
versions:
33+
# - all
34+
# - 16
35+
# - 17
36+
# - 18
37+
# - 19
38+
- 20
39+
- 21
40+
- 22
41+
- 23
42+
- 24
43+
#- name: opensuse
44+
# versions:
45+
# - all
46+
# - 12.1
47+
# - 12.2
48+
# - 12.3
49+
# - 13.1
50+
# - 13.2
51+
#- name: Amazon
52+
# versions:
53+
# - all
54+
# - 2013.03
55+
# - 2013.09
56+
#- name: GenericBSD
57+
# versions:
58+
# - all
59+
# - any
60+
#- name: FreeBSD
61+
# versions:
62+
# - all
63+
# - 8.0
64+
# - 8.1
65+
# - 8.2
66+
# - 8.3
67+
# - 8.4
68+
# - 9.0
69+
# - 9.1
70+
# - 9.1
71+
# - 9.2
72+
#- name: Ubuntu
73+
# versions:
74+
# - all
75+
# - lucid
76+
# - maverick
77+
# - natty
78+
# - oneiric
79+
# - precise
80+
# - quantal
81+
# - raring
82+
# - saucy
83+
# - trusty
84+
#- name: SLES
85+
# versions:
86+
# - all
87+
# - 10SP3
88+
# - 10SP4
89+
# - 11
90+
# - 11SP1
91+
# - 11SP2
92+
# - 11SP3
93+
#- name: GenericLinux
94+
# versions:
95+
# - all
96+
# - any
97+
#- name: Debian
98+
# versions:
99+
# - all
100+
# - etch
101+
# - lenny
102+
# - squeeze
103+
# - wheezy
104+
#
105+
# Below are all categories currently available. Just as with
106+
# the platforms above, uncomment those that apply to your role.
107+
#
108+
#categories:
109+
#- cloud
110+
#- cloud:ec2
111+
#- cloud:gce
112+
#- cloud:rax
113+
#- clustering
114+
#- database
115+
#- database:nosql
116+
#- database:sql
117+
#- development
118+
#- monitoring
119+
#- networking
120+
#- packaging
121+
#- system
122+
#- web
123+
dependencies: []
124+
# List your role dependencies here, one per line. Only
125+
# dependencies available via galaxy should be listed here.
126+
# Be sure to remove the '[]' above if you add dependencies
127+
# to this list.
128+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
- name: Copy Endpoint Zone Definitions
3+
template: src=endpoint_zones.j2
4+
dest={{ icinga2_zones_dir }}/{{ hostvars[item]['ansible_fqdn'] }}.conf
5+
owner=icinga
6+
group=icinga
7+
mode=0640
8+
with_items: "{{ groups['all'] }}"
9+
notify:
10+
- reload icinga2
11+
12+
- name: Copy Zone Definitions
13+
template:
14+
src: zone.j2
15+
dest: "{{ icinga2_zones_dir }}/{{ item }}.conf"
16+
owner: icinga
17+
group: icinga
18+
mode: 0640
19+
with_items: "{{ icinga_merged_zones }}"
20+
notify:
21+
- reload icinga2
22+
23+
- name: Copy zones.conf
24+
template:
25+
src: zones.conf
26+
dest: /etc/icinga2/zones.conf
27+
owner: icinga
28+
group: icinga
29+
mode: 0640
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# tasks file for icinga2-ansible-add-zones
3+
4+
- name: Ensure existance of {{ icinga2_zones_dir }}
5+
file:
6+
name: "{{ icinga2_zones_dir }}"
7+
state: directory
8+
owner: icinga
9+
group: icinga
10+
11+
- include: icinga2_add_zones.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Endpoint "{{ hostvars[item]['ansible_fqdn'] }}" {
2+
host = "{{ hostvars[item]['ansible_fqdn'] }}"
3+
}
4+
5+
{% if 'icinga_zone' in hostvars[item] %}
6+
object Zone "{{ hostvars[item]['ansible_fqdn'] }}" {
7+
endpoints = [ "{{ hostvars[item]['ansible_fqdn'] }}" ]
8+
{% if 'icinga_zone' in hostvars[item] %}
9+
parent = "{{ hostvars[item]['icinga_zone'] }}"
10+
{% else %}
11+
parent = "{{ icinga_master_zone }}"
12+
{% endif %}
13+
}
14+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Zone "{{ item }}" {
2+
{% if 'parent' in icinga_merged_zones[item] %}
3+
parent = "{{ icinga_merged_zones[item].parent }}"
4+
{% endif %}
5+
6+
endpoints = [
7+
{% for host, params in hostvars.iteritems() %}
8+
{% if item == icinga_master_zone and 'icinga_zone' not in params %}
9+
"{{ host }}",
10+
{% endif %}{% endfor %}
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include_recursive "zones.d"

0 commit comments

Comments
 (0)