From a1b2783a67c0dd1b3ff6ed4ccab14b1a4e10f24c Mon Sep 17 00:00:00 2001 From: Greg Sutcliffe Date: Thu, 31 Jul 2025 12:46:33 +0100 Subject: [PATCH] Zabbix: ensure existence of correct hostgroups also applies the correct hostgroups when creating/updating hosts Signed-off-by: Greg Sutcliffe --- inventory/group_vars/zabbix | 4 ++++ inventory/group_vars/zabbix_stg | 4 ++++ roles/zabbix/zabbix_agent/defaults/main.yml | 3 +++ roles/zabbix/zabbix_agent/tasks/hosts.yml | 3 +-- .../zabbix_server/tasks/configure_api.yml | 17 +++++++++++------ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/inventory/group_vars/zabbix b/inventory/group_vars/zabbix index 6a5b1a8374..e5c64bd23b 100644 --- a/inventory/group_vars/zabbix +++ b/inventory/group_vars/zabbix @@ -22,3 +22,7 @@ num_cpus: 4 tcp_ports: [80, 443] notes: Test instanec for zabbix server zabbix_matrix_roomid: "!dODrizXNtqWjiylAyh:fedora.im" +zabbix_base_hostgroups: +- All servers +- Linux servers +- Zabbix servers diff --git a/inventory/group_vars/zabbix_stg b/inventory/group_vars/zabbix_stg index 45e8e6b26f..b462f80387 100644 --- a/inventory/group_vars/zabbix_stg +++ b/inventory/group_vars/zabbix_stg @@ -22,3 +22,7 @@ num_cpus: 2 tcp_ports: [80, 443] notes: Test instance for zabbix server zabbix_stg_matrix_roomid: "!dODrizXNtqWjiylAyh:fedora.im" +zabbix_base_hostgroups: +- All servers +- Linux servers +- Zabbix servers diff --git a/roles/zabbix/zabbix_agent/defaults/main.yml b/roles/zabbix/zabbix_agent/defaults/main.yml index bd6e6a07f7..df4fd7fb5e 100644 --- a/roles/zabbix/zabbix_agent/defaults/main.yml +++ b/roles/zabbix/zabbix_agent/defaults/main.yml @@ -4,6 +4,9 @@ zabbix_host: "zabbix01{{ env_suffix }}.{{ datacenter }}.fedoraproject.org" zabbix_agent_hostname: "{{ ansible_hostname }}" zabbix_base_templates: - Linux by Zabbix agent active +zabbix_base_hostgroups: +- All servers +- Linux servers # TLS/PSK settings to encrypt between agent and proxy/server zabbix_tls_connect: "psk" diff --git a/roles/zabbix/zabbix_agent/tasks/hosts.yml b/roles/zabbix/zabbix_agent/tasks/hosts.yml index 4ab3a995bf..d770a643aa 100644 --- a/roles/zabbix/zabbix_agent/tasks/hosts.yml +++ b/roles/zabbix/zabbix_agent/tasks/hosts.yml @@ -24,8 +24,7 @@ - name: Create self in Zabbix community.zabbix.zabbix_host: host_name: "{{ inventory_hostname }}" - host_groups: - - Linux servers + host_groups: "{{ zabbix_base_hostgroups }}" link_templates: "{{ zabbix_base_templates }}" status: enabled state: present diff --git a/roles/zabbix/zabbix_server/tasks/configure_api.yml b/roles/zabbix/zabbix_server/tasks/configure_api.yml index 667881674d..b9265747a1 100644 --- a/roles/zabbix/zabbix_server/tasks/configure_api.yml +++ b/roles/zabbix/zabbix_server/tasks/configure_api.yml @@ -16,6 +16,15 @@ tags: - zabbix_configuration block: + - name: Setup host groups + community.zabbix.zabbix_group: + state: present + host_groups: + - All servers + - Linux servers + - Ping-only servers + - Zabbix servers + # Templates seem to always report a change :/ - name: Import all template files community.zabbix.zabbix_template: @@ -39,9 +48,7 @@ community.zabbix.zabbix_usergroup: name: Sysadmin-noc hostgroup_rights: - - host_group: Discovered hosts - permission: read-write - - host_group: Zabbix servers + - host_group: All servers permission: read-write templategroup_rights: - template_group: Fedora @@ -52,9 +59,7 @@ community.zabbix.zabbix_usergroup: name: Guests hostgroup_rights: - - host_group: Discovered hosts - permission: read-only - - host_group: Zabbix servers + - host_group: All servers permission: read-only templategroup_rights: - template_group: Fedora