---
- name: Kali Linux 快速健康检查
  hosts: kali
  become: yes
  gather_facts: yes
  
  tasks:
    - name: 显示系统基本信息
      debug:
        msg: |
          === Kali Linux 系统信息 ===
          主机名: {{ ansible_hostname }}
          操作系统: {{ ansible_distribution }} {{ ansible_distribution_version }}
          内核版本: {{ ansible_kernel }}
          架构: {{ ansible_architecture }}
          CPU核心数: {{ ansible_processor_vcpus }}
          内存总量: {{ ansible_memtotal_mb }} MB
          
    - name: 修复损坏的依赖关系
      command: apt --fix-broken install -y
      when: ansible_os_family == "Debian"
      ignore_errors: yes
      
    - name: 检查系统更新状态
      apt:
        update_cache: yes
        upgrade: dist
      check_mode: yes
      register: update_check
      changed_when: false
      ignore_errors: yes
      
    - name: 显示系统更新状态
      debug:
        msg: "{% if update_check.changed %}系统有可用更新{% else %}系统已是最新{% endif %}"
        
    - name: 检查磁盘空间
      command: "df -h /"
      register: disk_space
      
    - name: 显示根分区磁盘空间
      debug:
        msg: "根分区使用情况: {{ disk_space.stdout_lines[1] }}"
        
    - name: 检查关键Kali工具
      command: "which {{ item }}"
      loop:
        - nmap
        - metasploit-framework
        - wireshark
      register: tool_check
      ignore_errors: yes
      changed_when: false
      
    - name: 显示工具检查结果
      debug:
        msg: "{% for result in tool_check.results %}{{ result.item }}: {% if result.rc == 0 %}已安装{% else %}未安装{% endif %}{% endfor %}"
        
    - name: 检查网络连接
      uri:
        url: https://httpbin.org/get
        method: GET
        timeout: 5
      register: network_test
      ignore_errors: yes
      
    - name: 显示网络连接状态
      debug:
        msg: "{% if network_test.failed %}网络连接测试失败{% else %}网络连接正常{% endif %}"
        
    - name: 检查系统负载
      command: "uptime"
      register: uptime
      
    - name: 显示系统负载
      debug:
        msg: "系统负载: {{ uptime.stdout }}"
        
    - name: 检查SSH服务状态
      systemd:
        name: ssh
      register: ssh_service
      
    - name: 显示SSH服务状态
      debug:
        msg: "SSH服务状态: {{ ssh_service.status.ActiveState }}"