---
- name: Установка Zabbix Agent 2
  hosts: hip
  become: yes
  gather_facts: yes
  vars:
    zabbix_server_host: "zabbix.example.com"

  tasks:
    - name: Добавление репозитория Zabbix (Debian/Ubuntu)
      shell: |
        apt-get update
        apt-get install -y wget
        wget -O zabbix-release.deb https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian12_all.deb
        dpkg -i zabbix-release.deb
        apt-get update
      args:
        warn: no

    - name: Установка Zabbix Agent 2
      apt:
        name: zabbix-agent2
        state: present

    - name: Настройка Zabbix Agent 2
      lineinfile:
        path: /etc/zabbix/zabbix_agent2.conf
        regexp: "^{{ item.param }}="
        line: "{{ item.param }}={{ item.value }}"
      loop:
        - { param: "Server", value: "{{ zabbix_server_host }},11.200.0.0/24,88.80.32.24" }
        - { param: "ServerActive", value: "{{ zabbix_server_host }}" }
        - { param: "Hostname", value: "{{ inventory_hostname }}" }

    - name: Запуск сервиса
      systemd:
        name: zabbix-agent2
        state: restarted
        enabled: yes
