Skip to content

Commit f8119d3

Browse files
committed
feat(roles): validate Icinga 2 config before restart in icinga2_master and icingadb
Add a chained `icinga2 daemon --validate` handler that runs before the icinga2 restart in both roles. Tasks now notify the validate handler, which is defined ahead of the restart handler and chains into it, so a broken config fails the run loudly instead of bouncing the daemon into a down state. This closes the one gap versus the upstream Icinga install guides, which run `icinga2 daemon -C` before reloading.
1 parent 6c223bd commit f8119d3

5 files changed

Lines changed: 32 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
### Added
2323

24+
* **role:icinga2_master, role:icingadb, role:icingaweb2, role:icingaweb2_module_reporting, role:icingaweb2_module_x509**: Add explicit Ubuntu variable files, making Ubuntu support visible alongside Debian. The Icinga repository, GPG key and package names were verified on Debian 13 and Ubuntu 24.04.
2425
* **role:nextcloud**: Add `meta/argument_specs.yml` declaring the user-facing variables, so role-entry validation catches type mismatches and missing mandatory variables.
2526
* **role:clamav**: Add `meta/argument_specs.yml` declaring the user-facing variables, so role-entry validation catches type mismatches and unknown variables.
2627
* **role:core_dumps**: New role that disables core dumps (which can leak sensitive process memory to disk) following the CIS Benchmark recommendations. Runs as part of `setup_basic`.
@@ -68,6 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6869

6970
### Changed
7071

72+
* **role:icinga2_master, role:icingadb**: Validate the Icinga 2 configuration before restarting the service. A faulty config now fails the playbook run loudly instead of bouncing the daemon into a broken state and leaving Icinga 2 down.
7173
* **role:nextcloud**: Automatic app updates are now enabled by default (`nextcloud__timer_app_update_enabled`). The scheduled app update only switches Nextcloud into maintenance mode when an app update is actually pending, so an instance that is already up to date keeps serving requests without interruption. After updating, the recommended database migrations are applied automatically. A failed run no longer leaves the instance stuck in maintenance mode.
7274
* **role:clamav**: Now runs on Debian and Ubuntu in addition to Red Hat-family systems, and works on RHEL 10. The role seeds the signature database on first install so the scanner starts reliably, and runs an EICAR self-test (also available on its own via the `clamav:test` tag) that confirms detection actually works.
7375
* **role:sshd**: Ship hardened SSH defaults: X11 forwarding, agent forwarding and TCP keepalives are now off, `MaxAuthTries` is `3`, `ClientAliveCountMax` is `2`, and the log level is `VERBOSE`. All are overridable via the new `sshd__allow_agent_forwarding`, `sshd__allow_tcp_forwarding`, `sshd__client_alive_count_max`, `sshd__max_auth_tries`, `sshd__max_sessions`, `sshd__tcp_keep_alive` and `sshd__x11_forwarding` variables. Note: a client offering more than three keys from its SSH agent can be rejected by `MaxAuthTries 3`; use an explicit identity on the client or raise `sshd__max_auth_tries`.

roles/icinga2_master/handlers/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Validation runs before the restart: it is defined first, so when both are
2+
# notified in the same flush it executes first, and it chains into the restart.
3+
# `icinga2 daemon --validate` (-C) catches a broken config before the running
4+
# daemon is bounced, so a bad deploy fails loudly here instead of leaving icinga2
5+
# down after the restart.
6+
- name: 'icinga2_master: icinga2 daemon --validate'
7+
ansible.builtin.command: 'icinga2 daemon --validate'
8+
changed_when: true # must report changed so the chained restart handler is triggered
9+
notify: 'icinga2_master: restart icinga2'
10+
111
- name: 'icinga2_master: restart icinga2'
212
ansible.builtin.service:
313
name: 'icinga2'

roles/icinga2_master/tasks/main.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@
5454
owner: 'root'
5555
group: 'root'
5656
mode: 0o644
57-
notify: 'icinga2_master: restart icinga2'
57+
notify: 'icinga2_master: icinga2 daemon --validate'
5858
tags:
5959
- 'icinga2_master:api_users'
6060

6161
- name: 'icinga2 feature enable api'
6262
community.general.icinga2_feature:
6363
name: 'api'
6464
state: 'present'
65-
notify: 'icinga2_master: restart icinga2'
65+
notify: 'icinga2_master: icinga2 daemon --validate'
6666

6767
- name: 'icinga2 feature enable notification'
6868
community.general.icinga2_feature:
6969
name: 'notification'
7070
state: 'present'
71-
notify: 'icinga2_master: restart icinga2'
71+
notify: 'icinga2_master: icinga2 daemon --validate'
7272

7373
- name: 'Deploy /etc/icinga2/features-available/influxdb.conf'
7474
ansible.builtin.template:
@@ -78,13 +78,13 @@
7878
owner: '{{ icinga2_master__icinga_user }}'
7979
group: '{{ icinga2_master__icinga_user }}'
8080
mode: 0o640
81-
notify: 'icinga2_master: restart icinga2'
81+
notify: 'icinga2_master: icinga2 daemon --validate'
8282

8383
- name: 'icinga2 feature enable influxdb'
8484
community.general.icinga2_feature:
8585
name: 'influxdb'
8686
state: 'present'
87-
notify: 'icinga2_master: restart icinga2'
87+
notify: 'icinga2_master: icinga2 daemon --validate'
8888

8989
tags:
9090
- 'icinga2_master'
@@ -105,7 +105,7 @@
105105
args:
106106
creates: '/var/lib/icinga2/certs/{{ icinga2_master__cn }}.crt'
107107
register: 'icinga2_master__node_setup_result'
108-
notify: 'icinga2_master: restart icinga2'
108+
notify: 'icinga2_master: icinga2 daemon --validate'
109109

110110
- name: 'Output of the node setup'
111111
ansible.builtin.debug:
@@ -172,7 +172,7 @@
172172
{% endif %}
173173
args:
174174
creates: "/var/lib/icinga2/certs/{{ icinga2_master__cn }}.crt"
175-
notify: 'icinga2_master: restart icinga2'
175+
notify: 'icinga2_master: icinga2 daemon --validate'
176176

177177
- name: 'Make sure that the api-users.conf is included in /etc/icinga2/icinga2.conf'
178178
ansible.builtin.lineinfile:
@@ -198,7 +198,7 @@
198198
owner: '{{ icinga2_master__icinga_user }}'
199199
group: '{{ icinga2_master__icinga_user }}'
200200
mode: 0o640
201-
notify: 'icinga2_master: restart icinga2'
201+
notify: 'icinga2_master: icinga2 daemon --validate'
202202

203203
tags:
204204
- 'icinga2_master'

roles/icingadb/handlers/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Validation runs before the icinga2 restart: it is defined first, so when both
2+
# are notified in the same flush it executes first, and it chains into the
3+
# restart. `icinga2 daemon --validate` (-C) catches a broken icingadb feature
4+
# config before the running daemon is bounced, so a bad deploy fails loudly here
5+
# instead of leaving icinga2 down after the restart.
6+
- name: 'icingadb: icinga2 daemon --validate'
7+
ansible.builtin.command: 'icinga2 daemon --validate'
8+
changed_when: true # must report changed so the chained restart handler is triggered
9+
notify: 'icingadb: restart icinga2'
10+
111
- name: 'icingadb: restart icinga2'
212
ansible.builtin.service:
313
name: 'icinga2'

roles/icingadb/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
owner: '{{ icingadb__icinga_user }}'
3131
group: '{{ icingadb__icinga_user }}'
3232
mode: 0o640
33-
notify: 'icingadb: restart icinga2'
33+
notify: 'icingadb: icinga2 daemon --validate'
3434

3535
- name: 'Remove rpmnew / rpmsave (and Debian equivalents)'
3636
ansible.builtin.include_role:
@@ -43,7 +43,7 @@
4343
community.general.icinga2_feature:
4444
name: 'icingadb'
4545
state: 'present'
46-
notify: 'icingadb: restart icinga2'
46+
notify: 'icingadb: icinga2 daemon --validate'
4747

4848
- name: 'Flush handlers so that the icinga2 icingadb feature is active' # else /var/lib/icinga2/icingadb.env is missing later on
4949
ansible.builtin.meta: 'flush_handlers'

0 commit comments

Comments
 (0)