---
- name: Verify Zabbix Agent Installation
  hosts: all
  become: yes
  
  tasks:
    - name: Check service status
      shell: systemctl status zabbix-agent --no-pager -l | head -15
      register: service_status
      failed_when: false

    - name: Check port listening
      shell: ss -tlnp | grep 10050 || netstat -tlnp | grep 10050 || echo "Port not listening"
      register: port_status
      failed_when: false

    - name: Check agent version
      shell: zabbix_agentd --version 2>/dev/null | head -1 || echo "Version check failed"
      register: version_check
      failed_when: false

    - name: Test agent ping
      shell: zabbix_agentd -t agent.ping 2>/dev/null || echo "Ping test failed"
      register: ping_test
      failed_when: false

    - name: Check config file
      stat:
        path: /etc/zabbix/zabbix_agentd.conf
      register: config_file

    - name: Display verification results
      debug:
        msg:
          - "==================== {{ inventory_hostname }} ===================="
          - "System: {{ system_type | default('unknown') }}"
          - "Service Status:"
          - "{{ service_status.stdout_lines | join('\n') }}"
          - ""
          - "Port Status: {{ port_status.stdout }}"
          - "Version: {{ version_check.stdout }}"
          - "Ping Test: {{ ping_test.stdout }}"
          - "Config File Exists: {{ config_file.stat.exists }}"
          - "============================================================"
