This commit is contained in:
2026-02-16 11:25:04 +01:00
parent 4e44f544a6
commit b6ab200bdc
2 changed files with 64 additions and 13 deletions

View File

@@ -6,6 +6,7 @@
zabbix_db_file: "/var/lib/zabbix/zabbix_proxy.db" zabbix_db_file: "/var/lib/zabbix/zabbix_proxy.db"
zabbix_db_type: "sqlite" # sqlite | mysql | postgres zabbix_db_type: "sqlite" # sqlite | mysql | postgres
zabbix_api_url: "https://zabbix.sectorq.eu/api_jsonrpc.php" zabbix_api_url: "https://zabbix.sectorq.eu/api_jsonrpc.php"
clustename: debian
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}" become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
block: block:
# ========================================================== # ==========================================================
@@ -125,14 +126,12 @@
path: /etc/zabbix/zabbix_agent2.conf path: /etc/zabbix/zabbix_agent2.conf
regexp: "^{{ item.key }}=" regexp: "^{{ item.key }}="
line: "{{ item.key }}={{ item.value }}" line: "{{ item.key }}={{ item.value }}"
loop: >- loop:
{{ [ - { key: "Server", value: "127.0.0.1" }
{'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': 'ServerActive', 'value': 'debian13-vm01.home.lan;debian13-vm02.home.lan;debian13-vm03.home.lan;debian13-vm04.home.lan;debian13-vm05.home.lan'}, - { key: "Hostname", value: "{{ zabbix_proxy_name }}" }
{'key': 'Hostname', 'value': zabbix_proxy_name}, - { key: "HostMetadata", value: "linux,jaydee" }
{'key': 'HostMetadata', 'value': 'linux,jaydee'}, - { key: "SourceIP", value: "{{ ansible_default_ipv4.address }}" }
]
}}
# ========================================================== # ==========================================================
# Configure proxy # Configure proxy
@@ -184,6 +183,56 @@
state: restarted state: restarted
enabled: yes enabled: yes
- 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: Print proxygroup_check1
debug:
msg: "{{ proxygroup_check.json.result[0].proxy_groupid }}"
run_once: true
- 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 - name: Check if proxy exists
uri: uri:
url: "{{ zabbix_api_url }}" url: "{{ zabbix_api_url }}"
@@ -200,12 +249,11 @@
Content-Type: "application/json" Content-Type: "application/json"
Authorization: "Bearer {{ zabbix_auth_token }}" Authorization: "Bearer {{ zabbix_auth_token }}"
register: proxy_check register: proxy_check
- name: Print proxy_check - name: Print proxy_check
debug: debug:
msg: "{{ proxy_check }}" msg: "{{ proxy_check }}"
- name: Print ansible_default_ipv4.address
debug:
msg: "{{ ansible_default_ipv4.address }}"
- name: Create proxy if not exists - name: Create proxy if not exists
uri: uri:
@@ -217,7 +265,7 @@
method: "proxy.create" method: "proxy.create"
params: params:
name: "{{ zabbix_proxy_name }}" name: "{{ zabbix_proxy_name }}"
proxy_groupid: 1 proxy_groupid: "{{ proxygroup_check.json.result[0].proxy_groupid }}"
operating_mode: 0 operating_mode: 0
local_address: "{{ ansible_default_ipv4.address }}" local_address: "{{ ansible_default_ipv4.address }}"
port: "10051" port: "10051"

View File

@@ -7,4 +7,7 @@
when: ansible_facts.architecture is not defined when: ansible_facts.architecture is not defined
- name: Include OS-specific tasks - name: Include OS-specific tasks
ansible.builtin.include_tasks: "{{ ansible_distribution }}.yml" ansible.builtin.include_tasks: "{{ ansible_distribution }}.yml"
- name: Create hosts / proxies in zabbix
ansible.builtin.include_tasks: "configure.yml"