diff --git a/inventory/group_vars/zabbix b/inventory/group_vars/zabbix index 8205951367..1c0d0bd971 100644 --- a/inventory/group_vars/zabbix +++ b/inventory/group_vars/zabbix @@ -21,3 +21,15 @@ num_cpus: 4 # the host_vars/$hostname file tcp_ports: [80, 443] notes: Test instanec for zabbix server + +# Template defaults are defined in the template macros +# If we need a specific host to have different values for a macro, +# define it here + +# Use the macro name as it is in Zabbix so we can search for it easily + +# If you remove a key, Zabbix is *not* updated - set the value to +# "absent" instead + +# This is overriden at the host_var level +zabbix_macros: {} diff --git a/inventory/group_vars/zabbix_stg b/inventory/group_vars/zabbix_stg index 45e8e6b26f..c058f2be59 100644 --- a/inventory/group_vars/zabbix_stg +++ b/inventory/group_vars/zabbix_stg @@ -22,3 +22,15 @@ num_cpus: 2 tcp_ports: [80, 443] notes: Test instance for zabbix server zabbix_stg_matrix_roomid: "!dODrizXNtqWjiylAyh:fedora.im" + +# Template defaults are defined in the template macros +# If we need a specific host to have different values for a macro, +# define it here + +# Use the macro name as it is in Zabbix so we can search for it easily + +# If you remove a key, Zabbix is *not* updated - set the value to +# "absent" instead + +# This is overriden at the host_var level +zabbix_macros: {} diff --git a/inventory/host_vars/ipa02.stg.iad2.fedoraproject.org b/inventory/host_vars/ipa02.stg.iad2.fedoraproject.org index 7a438f34e2..5b678b0c89 100644 --- a/inventory/host_vars/ipa02.stg.iad2.fedoraproject.org +++ b/inventory/host_vars/ipa02.stg.iad2.fedoraproject.org @@ -8,3 +8,8 @@ ks_repo: https://infrastructure.fedoraproject.org/repo/rhel/RHEL9-x86_64/ ks_url: https://infrastructure.fedoraproject.org/repo/rhel/ks/kvm-rhel vmhost: vmhost-x86-02.stg.iad2.fedoraproject.org volgroup: /dev/vg_guests + +# see group_vars/zabbix_stg for details +zabbix_macros: + VFS.DEV.READ.AWAIT.WARN: 30 + VFS.DEV.WRITE.AWAIT.WARN: 30 diff --git a/inventory/host_vars/ipa03.stg.iad2.fedoraproject.org b/inventory/host_vars/ipa03.stg.iad2.fedoraproject.org index c430db777f..ad4e0ac293 100644 --- a/inventory/host_vars/ipa03.stg.iad2.fedoraproject.org +++ b/inventory/host_vars/ipa03.stg.iad2.fedoraproject.org @@ -8,3 +8,8 @@ ks_repo: https://infrastructure.fedoraproject.org/repo/rhel/RHEL9-x86_64/ ks_url: https://infrastructure.fedoraproject.org/repo/rhel/ks/kvm-rhel vmhost: vmhost-x86-02.stg.iad2.fedoraproject.org volgroup: /dev/vg_guests + +# see group_vars/zabbix_stg for details +zabbix_macros: + VFS.DEV.READ.AWAIT.WARN: 30 + VFS.DEV.WRITE.AWAIT.WARN: 30 diff --git a/roles/zabbix/zabbix_agent/tasks/macros.yml b/roles/zabbix/zabbix_agent/tasks/macros.yml new file mode 100644 index 0000000000..c9805f1748 --- /dev/null +++ b/roles/zabbix/zabbix_agent/tasks/macros.yml @@ -0,0 +1,23 @@ +--- +# This applies any host-level overrides to macro (variable) values in Zabbix. +# It's applied through the base agent role, but will work for the macros in +# *any* template, since unused macros will be ignored anyway. + +- name: Set Host-level macros + loop: "{{ lookup('dict', zabbix_macros, wantlist=True) }}" + vars: + ansible_zabbix_auth_key: "{{ (env == 'staging') | ternary(zabbix_stg_apikey, zabbix_apikey) }}" + ansible_network_os: community.zabbix.zabbix + ansible_connection: httpapi + ansible_httpapi_port: 443 + ansible_httpapi_use_ssl: true + ansible_httpapi_validate_certs: false + ansible_host: "{{ (env == 'staging') | ternary(zabbix_stg_hostname, zabbix_hostname) }}" + ansible_zabbix_url_path: "" + community.zabbix.zabbix_hostmacro: + host_name: "{{ inventory_hostname }}" + macro_name: "{{ item.key }}" + macro_value: "{{ item.value }}" + state: "{{ 'absent' if item.value == 'absent' else 'present' }}" + tags: + - zabbix_macros diff --git a/roles/zabbix/zabbix_agent/tasks/main.yml b/roles/zabbix/zabbix_agent/tasks/main.yml index c32742dd3b..592f23c16b 100644 --- a/roles/zabbix/zabbix_agent/tasks/main.yml +++ b/roles/zabbix/zabbix_agent/tasks/main.yml @@ -109,7 +109,7 @@ - zabbix_agent - name: Enabling Zabbix service - service: + ansible.builtin.service: name: "{{ item }}" state: started enabled: yes @@ -118,4 +118,10 @@ tags: - zabbix_agent -- include_tasks: tools.yml +- name: Configure Zabbix tools + ansible.builtin.include_tasks: tools.yml + +- name: Configure Zabbix macros / variables + ansible.builtin.include_tasks: macros.yml + tags: + - zabbix_macros