--- - name: Create or update a Zabbix host hosts: all gather_facts: yes tasks: - name: Authenticate with Zabbix API 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 register: auth_response delegate_to: localhost - name: Debug auth response debug: var: auth_response - name: Create or update a host in Zabbix 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" # Group ID for "Linux servers" templates: - templateid: "10001" # Template ID for "Template OS Linux" tls_connect: 2 tls_accept: 2 tls_psk_identity: "PSK-{{ inventory_hostname }}" tls_psk: "4e616d656461706c617965722072616e646f6d6b65792067656e657261746564" # Example PSK auth: "{{ auth_response.json.result }}" id: 1 delegate_to: localhost when: auth_response.json.result is defined