check-system.yml 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. ---
  2. # 系统信息检查
  3. - name: System Information
  4. hosts: "{{ target_hosts | default('all') }}"
  5. gather_facts: yes
  6. tasks:
  7. - name: Display OS info
  8. debug:
  9. msg: "OS: {{ ansible_facts['distribution'] }} {{ ansible_facts['distribution_version'] }}"
  10. - name: Display hostname
  11. debug:
  12. msg: "Hostname: {{ ansible_facts['hostname'] }}"
  13. - name: Display IP addresses
  14. debug:
  15. msg: "IP: {{ ansible_facts['default_ipv4']['address'] }}"
  16. - name: Display memory info
  17. debug:
  18. msg: "Memory: {{ (ansible_facts['memtotal_mb'] / 1024) | round(2) }} GB"
  19. - name: Display CPU info
  20. debug:
  21. msg: "CPU: {{ ansible_facts['processor_vcpus'] }} vCPUs"
  22. - name: Display disk space
  23. debug:
  24. msg: "Disk: {{ ansible_facts['mounts'][0]['size_total'] | default(0) | int / 1024 / 1024 / 1024 | round(2) }} GB"
  25. - name: Uptime
  26. command: uptime -s
  27. register: uptime
  28. - name: Show uptime
  29. debug:
  30. msg: "Uptime since: {{ uptime.stdout }}"