Skip to content

Commit

Permalink
Adding support for zabbix host macros per ansible inventory
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Arrotin <arrfab@centos.org>
  • Loading branch information
arrfab committed Nov 29, 2021
1 parent c919004 commit be532e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ zabbix_agent_tls: False
zabbix_agent_tls_psk: # gen with `openssl rand -hex 32` and also known by zabbix server
zabbix_agent_tls_psk_identity: # Whatever makes sense to you and known by zabbix server

# Zabbix host macros we want to control through ansible
# This is just a list of zabbix macro name and value to update
# example:
# zabbix_host_macros:
# - name: foo
# value: 5
# Empty list by default so nothing to add/modify
zabbix_host_macros: []
18 changes: 18 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,21 @@
- pkg_install is not changed
- zabbix_api_srv is defined
- zabbix_api_srv != 'None'

# applying host macros if defined
- name: Reflecting host macros in zabbix
command:
cmd: "/usr/libexec/centos/zabbix_host_tool
-n {{ inventory_hostname }}
-m {{ item.name }}
-v {{ item.value }}
"
with_items: "{{ zabbix_host_macros }}"
register: zbx_macros_result
changed_when: "zbx_macros_result.rc == 2"
failed_when: "zbx_macros_result.rc == 1"
delegate_to: "{{ zabbix_api_srv }}"
when:
- zabbix_api_srv is defined
- zabbix_api_srv != 'None'

0 comments on commit be532e3

Please sign in to comment.