From 4d0a89d1fd71132b548bb4d3d92ed656f7f3a0f1 Mon Sep 17 00:00:00 2001 From: Greg Sutcliffe Date: Thu, 2 Oct 2025 13:25:12 +0100 Subject: [PATCH] Zabbix: Make agent service handler global We have some hosts that do not include the zabbix_agent role which means they cannot find the restart handler for things like the postfix monitoring - and even then the restart would fail because the agent service doesn't exist This adds a global handler that is allowed to fail if the service is missing, but otherwise should fail normally for other problems This can probably be changed once we have zabbix everywhere... Signed-off-by: Greg Sutcliffe --- handlers/restart_services.yml | 11 +++++++++++ roles/zabbix/zabbix_agent/handlers/main.yml | 3 --- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/handlers/restart_services.yml b/handlers/restart_services.yml index 131edb1e54..b25777f306 100644 --- a/handlers/restart_services.yml +++ b/handlers/restart_services.yml @@ -185,3 +185,14 @@ - name: Restart debuginfod service: name=debuginfod state=restarted + +# This is allowed to fail when the zabbix agent is not found +# as it may be triggered from hosts without the zabbix_agent role +- name: Restart zabbix agent + ansible.builtin.systemd: + name: zabbix-agent + state: restarted + register: zabbix_restart + failed_when: + - zabbix_restart.failed + - "'Could not find' not in zabbix_restart.msg" diff --git a/roles/zabbix/zabbix_agent/handlers/main.yml b/roles/zabbix/zabbix_agent/handlers/main.yml index a0448dac71..8383f1f782 100644 --- a/roles/zabbix/zabbix_agent/handlers/main.yml +++ b/roles/zabbix/zabbix_agent/handlers/main.yml @@ -1,7 +1,4 @@ --- -- name: Restart zabbix agent - service: name=zabbix-agent state=restarted - - name: Reload custom selinux files ansible.builtin.shell: /usr/sbin/semodule -u "/etc/selinux/centos/centos-zabbix-agent.pp" when: ansible_selinux.mode == "enforcing"