This commit is contained in:
2026-02-16 12:16:27 +01:00
parent 3a7829aff2
commit 085e8a3c9c
3 changed files with 94 additions and 3 deletions

View File

@@ -0,0 +1 @@
zabbix_api_url: "https://zabbix.sectorq.eu/api_jsonrpc.php"

View File

@@ -2,7 +2,6 @@
vars:
zabbix_version: "7.4"
zabbix_server_ip: "192.168.77.101"
zabbix_proxy_name: "{{ inventory_hostname }}"
zabbix_db_file: "/var/lib/zabbix/zabbix_proxy.db"
zabbix_db_type: "sqlite" # sqlite | mysql | postgres
zabbix_api_url: "https://zabbix.sectorq.eu/api_jsonrpc.php"
@@ -133,7 +132,7 @@
loop:
- { key: "Server", value: "127.0.0.1" }
- { key: "ServerActive", value: "{{ clustename }}-vm01.home.lan;{{ clustename }}-vm02.home.lan;{{ clustename }}-vm03.home.lan;{{ clustename }}-vm04.home.lan;{{ clustename }}-vm05.home.lan" }
- { key: "Hostname", value: "{{ zabbix_proxy_name }}" }
- { key: "Hostname", value: "{{ inventory_hostname }}" }
- { key: "HostMetadata", value: "linux,jaydee" }
- { key: "SourceIP", value: "{{ ansible_default_ipv4.address }}" }
@@ -150,7 +149,7 @@
{{
[
{'key': 'Server', 'value': zabbix_server_ip},
{'key': 'Hostname', 'value': zabbix_proxy_name},
{'key': 'Hostname', 'value': inventory_hostname},
{'key': 'ProxyMode', 'value': '0'}
]
+

View File

@@ -0,0 +1,91 @@
---
- name: Check if proxy group exists
uri:
url: "{{ zabbix_api_url }}"
method: POST
body_format: json
body:
jsonrpc: "2.0"
method: "proxygroup.get"
params:
filter:
name: "{{ clustename }}"
id: 2
headers:
Content-Type: "application/json"
Authorization: "Bearer {{ zabbix_auth_token }}"
register: proxygroup_check
run_once: true # Run this task only once
- name: Create proxy group if not exists
uri:
url: "{{ zabbix_api_url }}"
method: POST
body_format: json
body:
jsonrpc: "2.0"
method: "proxygroup.create"
params:
name: "{{ clustename }}"
failover_delay: "5m"
min_online: 1
id: 1
headers:
Content-Type: "application/json"
Authorization: "Bearer {{ zabbix_auth_token }}"
when: proxygroup_check.json.result | length == 0
register: proxygroup_check2
run_once: true # Run this task only once
- name: Print proxygroup_check2
debug:
msg: "{{ proxygroup_check.json.result[0].proxy_groupid }}"
run_once: true
- name: Check if proxy exists
uri:
url: "{{ zabbix_api_url }}"
method: POST
body_format: json
body:
jsonrpc: "2.0"
method: "proxy.get"
params:
filter:
name: "{{ inventory_hostname }}"
id: 2
headers:
Content-Type: "application/json"
Authorization: "Bearer {{ zabbix_auth_token }}"
register: proxy_check
- name: Print proxy_check
debug:
msg: "{{ proxy_check }}"
- name: Create proxy if not exists
uri:
url: "{{ zabbix_api_url }}"
method: POST
body_format: json
body:
jsonrpc: "2.0"
method: "proxy.create"
params:
name: "{{ inventory_hostname }}"
proxy_groupid: "{{ proxygroup_check.json.result[0].proxy_groupid }}"
operating_mode: 0
local_address: "{{ ansible_default_ipv4.address }}"
port: "10051"
id: 3
headers:
Content-Type: "application/json"
Authorization: "Bearer {{ zabbix_auth_token }}"
when: proxy_check.json.result | length == 0
register: proxy_check2
- name: Print proxy_check
debug:
msg: "{{ proxy_check2 }}"