mirror of
https://gitlab.sectorq.eu/jaydee/ansible.git
synced 2026-03-13 13:42:47 +01:00
build
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
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"
|
||||
zabbix_var_lib_path: "/var/lib/zabbix"
|
||||
zabbix_config_path: "/etc/zabbix"
|
||||
zabbix_log_path: "/var/log/zabbix"
|
||||
clustename: rocky9
|
||||
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
|
||||
block:
|
||||
# ==========================================================
|
||||
@@ -18,9 +16,13 @@
|
||||
- name: Gather facts
|
||||
ansible.builtin.setup:
|
||||
|
||||
- name: Set proxy group name
|
||||
set_fact:
|
||||
clustename: "rocky9"
|
||||
|
||||
- name: Set proxy name
|
||||
set_fact:
|
||||
clustename: "rocky"
|
||||
clustename: "rocky9"
|
||||
|
||||
- name: Show default IP
|
||||
ansible.builtin.debug:
|
||||
@@ -144,7 +146,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 }}" }
|
||||
|
||||
@@ -162,7 +164,7 @@
|
||||
{{
|
||||
[
|
||||
{'key': 'Server', 'value': zabbix_server_ip},
|
||||
{'key': 'Hostname', 'value': zabbix_proxy_name},
|
||||
{'key': 'Hostname', 'value': inventory_hostname },
|
||||
{'key': 'ProxyMode', 'value': '0'}
|
||||
]
|
||||
+
|
||||
@@ -227,103 +229,5 @@
|
||||
state: restarted
|
||||
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
|
||||
uri:
|
||||
url: "{{ zabbix_api_url }}"
|
||||
method: POST
|
||||
body_format: json
|
||||
body:
|
||||
jsonrpc: "2.0"
|
||||
method: "proxy.get"
|
||||
params:
|
||||
filter:
|
||||
name: "{{ zabbix_proxy_name }}"
|
||||
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: "{{ zabbix_proxy_name }}"
|
||||
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 }}"
|
||||
|
||||
- name: Create hosts / proxies in zabbix
|
||||
ansible.builtin.include_tasks: "configure.yml"
|
||||
|
||||
Reference in New Issue
Block a user