58 lines
1.6 KiB
YAML
58 lines
1.6 KiB
YAML
---
|
|
- name: Create or update a Zabbix host
|
|
hosts: all
|
|
gather_facts: true
|
|
tasks:
|
|
- name: Authenticate with Zabbix API
|
|
register: auth_response
|
|
delegate_to: localhost
|
|
ansible.builtin.uri:
|
|
url: http://192.168.1.24/api_jsonrpc.php
|
|
method: POST
|
|
body_format: json
|
|
headers:
|
|
Content-Type: application/json
|
|
body:
|
|
jsonrpc: "2.0"
|
|
method: user.login
|
|
params:
|
|
username: Admin
|
|
password: zabbix
|
|
id: 1
|
|
|
|
- name: Debug auth response
|
|
ansible.builtin.debug:
|
|
var: auth_response
|
|
|
|
- name: Create or update a host in Zabbix
|
|
delegate_to: localhost
|
|
when: auth_response.json.result is defined
|
|
ansible.builtin.uri:
|
|
url: http://192.168.1.24/api_jsonrpc.php
|
|
method: POST
|
|
body_format: json
|
|
headers:
|
|
Content-Type: application/json
|
|
body:
|
|
jsonrpc: "2.0"
|
|
method: host.create
|
|
params:
|
|
host: "{{ inventory_hostname }}"
|
|
interfaces:
|
|
- type: 1
|
|
main: 1
|
|
useip: 1
|
|
ip: "{{ ansible_default_ipv4.address }}"
|
|
dns: ""
|
|
port: "10050"
|
|
groups:
|
|
- groupid: "2"
|
|
templates:
|
|
- templateid: "10001"
|
|
tls_connect: 2
|
|
tls_accept: 2
|
|
tls_psk_identity: PSK-{{ inventory_hostname }}
|
|
tls_psk: 4e616d656461706c617965722072616e646f6d6b65792067656e657261746564
|
|
auth: "{{ auth_response.json.result }}"
|
|
id: 1
|