| 1 |
--- |
| 2 |
# tasks file for zabbix_proxy |
| 3 |
- name: "Include OS-specific variables" |
| 4 |
ansible.builtin.include_vars: "{{ ansible_facts['os_family'] }}.yml" |
| 5 |
tags: |
| 6 |
- always |
| 7 |
|
| 8 |
- name: Determine Latest Supported Zabbix Version |
| 9 |
ansible.builtin.set_fact: |
| 10 |
zabbix_proxy_version: "{{ zabbix_valid_proxy_versions[ansible_facts['distribution_major_version']][0] | default(7.2) }}" |
| 11 |
when: zabbix_proxy_version is not defined or zabbix_proxy_version is none |
| 12 |
tags: |
| 13 |
- always |
| 14 |
|
| 15 |
- name: Set More Variables |
| 16 |
ansible.builtin.set_fact: |
| 17 |
zabbix_proxy_db_long: "{{ 'postgresql' if zabbix_proxy_database == 'pgsql' else zabbix_proxy_database }}" |
| 18 |
zabbix_proxy_fpinglocation: "{{ zabbix_proxy_fpinglocation if zabbix_proxy_fpinglocation is defined else _zabbix_proxy_fpinglocation}}" |
| 19 |
zabbix_proxy_fping6location: "{{ zabbix_proxy_fping6location if zabbix_proxy_fping6location is defined else _zabbix_proxy_fping6location}}" |
| 20 |
tags: |
| 21 |
- always |
| 22 |
|
| 23 |
- name: Check that version is supported |
| 24 |
when: zabbix_proxy_version_check | bool |
| 25 |
ansible.builtin.assert: |
| 26 |
that: |
| 27 |
- zabbix_proxy_version|float in zabbix_valid_proxy_versions[ ansible_facts['distribution_major_version'] ] |
| 28 |
fail_msg: Zabbix version {{ zabbix_proxy_version }} is not supported on {{ ansible_facts['distribution'] }} {{ ansible_facts['distribution_major_version'] }} |
| 29 |
tags: |
| 30 |
- always |
| 31 |
|
| 32 |
- name: "Set default ip address for zabbix_proxy_ip" |
| 33 |
ansible.builtin.set_fact: |
| 34 |
zabbix_proxy_ip: "{{ ansible_facts['default_ipv4'].address | default(ansible_facts['all_ipv4_addresses'][0]) }}" |
| 35 |
when: |
| 36 |
- zabbix_proxy_ip is not defined |
| 37 |
- ansible_facts['default_ipv4'].address is defined or ansible_facts['all_ipv4_addresses'] | length > 0 |
| 38 |
tags: |
| 39 |
- install |
| 40 |
- config |
| 41 |
- api |
| 42 |
|
| 43 |
- name: Install Repository |
| 44 |
ansible.builtin.include_role: |
| 45 |
name: community.zabbix.zabbix_repo |
| 46 |
vars: |
| 47 |
zabbix_repo_version: "{{ zabbix_proxy_version }}" |
| 48 |
zabbix_repo_package: "zabbix-proxy-{{ zabbix_proxy_database }}" |
| 49 |
when: zabbix_manage_repo | default(true) |
| 50 |
|
| 51 |
- name: "Configure SELinux when enabled" |
| 52 |
ansible.builtin.include_tasks: selinux.yml |
| 53 |
when: ansible_facts.selinux.status | default('disabled') == 'enabled' |
| 54 |
|
| 55 |
- name: "Install zabbix-proxy packages" |
| 56 |
ansible.builtin.package: |
| 57 |
name: "{{ _zabbix_proxy_packages }}" |
| 58 |
state: "{{ zabbix_proxy_package_state }}" |
| 59 |
update_cache: true |
| 60 |
disablerepo: "{{ zabbix_proxy_disable_repo | default(_zabbix_proxy_disable_repo | default(omit)) }}" |
| 61 |
environment: |
| 62 |
http_proxy: "{{ zabbix_http_proxy | default('') }}" |
| 63 |
https_proxy: "{{ zabbix_https_proxy | default('') }}" |
| 64 |
register: _zabbix_proxy_package_installed |
| 65 |
until: _zabbix_proxy_package_installed is succeeded |
| 66 |
become: true |
| 67 |
tags: |
| 68 |
- install |
| 69 |
|
| 70 |
- name: "Initialize the database" |
| 71 |
ansible.builtin.include_tasks: "initialize-{{ zabbix_proxy_database }}.yml" |
| 72 |
|
| 73 |
- name: "Create directories" |
| 74 |
ansible.builtin.file: |
| 75 |
state: directory |
| 76 |
path: "{{ item.path }}" |
| 77 |
owner: "{{ zabbix_os_user }}" |
| 78 |
group: "{{ zabbix_os_user }}" |
| 79 |
mode: "{{ item.mode | default('0755') }}" |
| 80 |
become: true |
| 81 |
loop: |
| 82 |
- path: "{{ zabbix_proxy_include_dir }}" |
| 83 |
mode: "{{ zabbix_proxy_include_mode }}" |
| 84 |
- path: "{{ zabbix_proxy_loadmodulepath }}" |
| 85 |
- required: "{{ zabbix_proxy_tlspskfile is defined }}" |
| 86 |
path: "{{ zabbix_proxy_tlspskfile | default('/path/to/zabbix_proxy_tlspskfile/zabbix_proxy.psk') | dirname }}" |
| 87 |
loop_control: |
| 88 |
label: "{{ item.path }}" |
| 89 |
when: item.required | default(true) |
| 90 |
tags: |
| 91 |
- install |
| 92 |
- config |
| 93 |
|
| 94 |
- name: "Place TLS PSK File" |
| 95 |
ansible.builtin.copy: |
| 96 |
dest: "{{ zabbix_proxy_tlspskfile }}" |
| 97 |
content: "{{ zabbix_proxy_tlspsk_secret }}" |
| 98 |
owner: "{{ zabbix_os_user }}" |
| 99 |
group: "{{ zabbix_os_user }}" |
| 100 |
mode: 0400 |
| 101 |
become: true |
| 102 |
when: |
| 103 |
- zabbix_proxy_tlspskfile is defined |
| 104 |
- zabbix_proxy_tlspsk_secret is defined |
| 105 |
notify: |
| 106 |
- restart zabbix-proxy |
| 107 |
tags: |
| 108 |
- config |
| 109 |
|
| 110 |
- name: "Configure zabbix-proxy" |
| 111 |
ansible.builtin.template: |
| 112 |
src: zabbix_proxy.conf.j2 |
| 113 |
dest: "{{ zabbix_proxy_config }}" |
| 114 |
owner: "{{ zabbix_os_user }}" |
| 115 |
group: "{{ zabbix_os_user }}" |
| 116 |
mode: "{{ zabbix_proxy_conf_mode }}" |
| 117 |
notify: restart zabbix-proxy |
| 118 |
become: true |
| 119 |
tags: |
| 120 |
- config |
| 121 |
|
| 122 |
- name: Ensure proxy definition is up-to-date (added/updated/removed) for Zabbix < 7.0 |
| 123 |
vars: |
| 124 |
ansible_network_os: community.zabbix.zabbix |
| 125 |
ansible_connection: httpapi |
| 126 |
ansible_httpapi_use_ssl: "{{ zabbix_api_use_ssl }}" |
| 127 |
# --- Basic Auth (Begin) --- |
| 128 |
http_login_user: "{{ zabbix_api_http_user | default(-42) }}" |
| 129 |
http_login_password: "{{ zabbix_api_http_password | default(-42) }}" |
| 130 |
# --- Basic Auth (End) --- |
| 131 |
ansible_user: "{{ zabbix_api_login_user }}" |
| 132 |
ansible_httpapi_pass: "{{ zabbix_api_login_pass }}" |
| 133 |
ansible_httpapi_port: "{{ zabbix_api_server_port }}" |
| 134 |
ansible_httpapi_validate_certs: "{{ zabbix_api_validate_certs }}" |
| 135 |
community.zabbix.zabbix_proxy: |
| 136 |
state: "{{ zabbix_proxy_state }}" |
| 137 |
status: "{{ zabbix_proxy_status }}" |
| 138 |
proxy_name: "{{ zabbix_proxy_hostname }}" |
| 139 |
description: "{{ zabbix_proxy_description | default(omit) }}" |
| 140 |
interface: "{{ zabbix_proxy_interface }}" |
| 141 |
tls_psk: "{{ zabbix_proxy_tlspsk_secret | default(omit) }}" |
| 142 |
tls_psk_identity: "{{ zabbix_proxy_tlspskidentity | default(omit) }}" |
| 143 |
tls_subject: "{{ zabbix_proxy_tls_subject | default(omit) }}" |
| 144 |
tls_connect: "{{ zabbix_proxy_tls_config[zabbix_proxy_tlsaccept | default('no_encryption')] }}" |
| 145 |
tls_accept: "{{ zabbix_proxy_tls_config[zabbix_proxy_tlsconnect | default('no_encryption')] }}" |
| 146 |
when: |
| 147 |
- zabbix_api_create_proxy | bool |
| 148 |
- zabbix_proxy_version is version('7.0', '<') |
| 149 |
delegate_to: "{{ zabbix_api_server_host }}" |
| 150 |
tags: |
| 151 |
- api |
| 152 |
|
| 153 |
- name: Create Zabbix Proxy Group for Zabbix >= 7.0 |
| 154 |
run_once: true |
| 155 |
vars: |
| 156 |
gather_facts: false |
| 157 |
ansible_network_os: community.zabbix.zabbix |
| 158 |
ansible_connection: httpapi |
| 159 |
ansible_httpapi_use_ssl: "{{ zabbix_api_use_ssl }}" |
| 160 |
# --- Basic Auth (Begin) --- |
| 161 |
http_login_user: "{{ zabbix_api_http_user | default(-42) }}" |
| 162 |
http_login_password: "{{ zabbix_api_http_password | default(-42) }}" |
| 163 |
# --- Basic Auth (End) --- |
| 164 |
ansible_user: "{{ zabbix_api_login_user }}" |
| 165 |
ansible_httpapi_pass: "{{ zabbix_api_login_pass }}" |
| 166 |
ansible_httpapi_port: "{{ zabbix_api_server_port }}" |
| 167 |
ansible_httpapi_validate_certs: "{{ zabbix_api_validate_certs }}" |
| 168 |
community.zabbix.zabbix_proxy_group: |
| 169 |
description: "{{ zabbix_proxy_group_description | default(omit) }}" |
| 170 |
failover_delay: "{{ zabbix_proxy_group_failover_delay }}" |
| 171 |
min_online: "{{ zabbix_proxy_group_min_online }}" |
| 172 |
name: "{{ zabbix_proxy_group_name }}" |
| 173 |
state: "{{ zabbix_proxy_group_state }}" |
| 174 |
when: |
| 175 |
- zabbix_api_create_proxy_group | bool |
| 176 |
- zabbix_proxy_version is version('7.0', '>=') |
| 177 |
delegate_to: "{{ zabbix_api_server_host }}" |
| 178 |
tags: |
| 179 |
- api |
| 180 |
|
| 181 |
- name: Ensure proxy definition is up-to-date (added/updated/removed) for Zabbix >= 7.0 |
| 182 |
vars: |
| 183 |
gather_facts: false |
| 184 |
ansible_network_os: community.zabbix.zabbix |
| 185 |
ansible_connection: httpapi |
| 186 |
ansible_httpapi_use_ssl: "{{ zabbix_api_use_ssl }}" |
| 187 |
# --- Basic Auth (Begin) --- |
| 188 |
http_login_user: "{{ zabbix_api_http_user | default(-42) }}" |
| 189 |
http_login_password: "{{ zabbix_api_http_password | default(-42) }}" |
| 190 |
# --- Basic Auth (End) --- |
| 191 |
ansible_user: "{{ zabbix_api_login_user }}" |
| 192 |
ansible_httpapi_pass: "{{ zabbix_api_login_pass }}" |
| 193 |
ansible_httpapi_port: "{{ zabbix_api_server_port }}" |
| 194 |
ansible_httpapi_validate_certs: "{{ zabbix_api_validate_certs }}" |
| 195 |
community.zabbix.zabbix_proxy: |
| 196 |
state: "{{ zabbix_proxy_state }}" |
| 197 |
operating_mode: "{{ zabbix_proxy_status }}" |
| 198 |
proxy_name: "{{ zabbix_proxy_hostname }}" |
| 199 |
description: "{{ zabbix_proxy_description | default(omit) }}" |
| 200 |
address: "{{ zabbix_proxy_interface['ip'] }}" |
| 201 |
port: "{{ zabbix_proxy_interface['port'] }}" |
| 202 |
local_address: "{{ zabbix_api_create_proxy_group | ternary(zabbix_proxy_hostname, omit) }}" |
| 203 |
local_port: "{{ zabbix_api_create_proxy_group | ternary(zabbix_proxy_local_port, omit) }}" |
| 204 |
allowed_addresses: "{{ zabbix_proxy_allowed_addresses | default(omit) }}" |
| 205 |
custom_timeouts: "{{ zabbix_proxy_custom_timeouts | default(omit) }}" |
| 206 |
timeout_zabbix_agent: "{{ zabbix_proxy_timeout_zabbix_agent | default(omit) }}" |
| 207 |
timeout_simple_check: "{{ zabbix_proxy_timeout_simple_check | default(omit) }}" |
| 208 |
timeout_snmp_agent: "{{ zabbix_proxy_timeout_snmp_agent | default(omit) }}" |
| 209 |
timeout_external_check: "{{ zabbix_proxy_timeout_external_check | default(omit) }}" |
| 210 |
timeout_db_monitor: "{{ zabbix_proxy_timeout_db_monitor | default(omit) }}" |
| 211 |
timeout_http_agent: "{{ zabbix_proxy_timeout_http_agent | default(omit) }}" |
| 212 |
timeout_ssh_agent: "{{ zabbix_proxy_timeout_ssh_agent | default(omit) }}" |
| 213 |
timeout_telnet_agent: "{{ zabbix_proxy_timeout_telnet_agent | default(omit) }}" |
| 214 |
timeout_script: "{{ zabbix_proxy_timeout_script | default(omit) }}" |
| 215 |
timeout_browser: "{{ zabbix_proxy_timeout_browser | default(omit) }}" |
| 216 |
tls_connect: "{{ zabbix_proxy_tls_config[zabbix_proxy_tlsaccept | default('no_encryption')] }}" |
| 217 |
tls_accept: "{{ zabbix_proxy_tls_config[zabbix_proxy_tlsconnect | default('no_encryption')] }}" |
| 218 |
tls_psk: "{{ zabbix_proxy_tlspsk_secret | default(omit) }}" |
| 219 |
tls_psk_identity: "{{ zabbix_proxy_tlspskidentity | default(omit) }}" |
| 220 |
ca_cert: "{{ zabbix_proxy_ca_cert | default(omit) }}" |
| 221 |
tls_subject: "{{ zabbix_proxy_tls_subject | default(omit) }}" |
| 222 |
proxy_group: "{{ zabbix_api_create_proxy_group | ternary(zabbix_proxy_group_name, omit) }}" |
| 223 |
when: |
| 224 |
- zabbix_api_create_proxy | bool |
| 225 |
- zabbix_proxy_version is version('7.0', '>=') |
| 226 |
delegate_to: "{{ zabbix_api_server_host }}" |
| 227 |
tags: |
| 228 |
- api |
| 229 |
|
| 230 |
- name: "zabbix-proxy started" |
| 231 |
ansible.builtin.service: |
| 232 |
name: zabbix-proxy |
| 233 |
state: started |
| 234 |
enabled: true |
| 235 |
become: true |
| 236 |
when: zabbix_proxy_manage_service | bool |
| 237 |
tags: |
| 238 |
- service |