The `hostname.yml` task has been updated to use a variable `dest_hosts` instead of hardcoding the localhost. This allows for more flexibility in specifying the destination hosts, making it easier to manage and reuse configurations.
99 lines
3.8 KiB
YAML
99 lines
3.8 KiB
YAML
- hosts: "{{ dest_hosts }}"
|
|
gather_facts: yes
|
|
tasks:
|
|
|
|
# ----------------------------------------------------------------------
|
|
# 1. SYSTEM INFORMATION SUMMARY
|
|
# ----------------------------------------------------------------------
|
|
- name: Display Grouped System Information
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
System Information
|
|
-------------------------
|
|
Hostname : {{ ansible_hostname }}
|
|
FQDN : {{ ansible_fqdn }}
|
|
OS Family : {{ ansible_os_family }}
|
|
Architecture : {{ ansible_architecture }}
|
|
Total Memory : {{ ansible_memtotal_mb }} MB
|
|
|
|
Processor Model:
|
|
{% for cpu in ansible_processor | unique %}
|
|
{% if cpu is string %}
|
|
- {{ cpu }}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
Core Count: {{ ansible_processor_cores }}
|
|
|
|
# ----------------------------------------------------------------------
|
|
# 2. NETWORK INFORMATION
|
|
# ----------------------------------------------------------------------
|
|
- name: Show Default IPv4 Info
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
Default IPv4 Info:
|
|
Address : {{ ansible_default_ipv4.address }}
|
|
Interface : {{ ansible_default_ipv4.interface }}
|
|
Gateway : {{ ansible_default_ipv4.gateway }}
|
|
Netmask : {{ ansible_default_ipv4.netmask }}
|
|
|
|
- name: Show All Network Interfaces
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
Network Interfaces:
|
|
{{ ansible_interfaces | join('\n - ') }}
|
|
|
|
- name: Show Details for Each Interface (Excluding Loopback)
|
|
ansible.builtin.debug:
|
|
var: hostvars['localhost']['ansible_' + item]
|
|
loop: "{{ ansible_interfaces }}"
|
|
when: hostvars['localhost']['ansible_' + item] is defined and item not in ['lo']
|
|
|
|
# ----------------------------------------------------------------------
|
|
# 3. STORAGE INFORMATION
|
|
# ----------------------------------------------------------------------
|
|
- name: Display Mounted Filesystems Summary (Safely)
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
Mounted Filesystems
|
|
=========================
|
|
{% for mount in ansible_mounts %}
|
|
Mount Point : {{ mount.mount }}
|
|
Device : {{ mount.device }}
|
|
Fstype : {{ mount.fstype }}
|
|
{% if mount.size_total is defined and mount.size_used is defined and mount.fstype not in ['tmpfs', 'overlay', 'squashfs'] %}
|
|
Size Total : {{ (mount.size_total | int // (1024 * 1024)) }} MB
|
|
Size Used : {{ (mount.size_used | int // (1024 * 1024)) }} MB
|
|
Size Avail : {{ ((mount.size_total | int - mount.size_used | int) // (1024 * 1024)) }} MB
|
|
{% else %}
|
|
Size Info : Not Available
|
|
{% endif %}
|
|
-------------------------
|
|
{% endfor %}
|
|
|
|
# ----------------------------------------------------------------------
|
|
# 4. CURRENT USER DETAILS
|
|
# ----------------------------------------------------------------------
|
|
- name: Show Connection and Effective User Details
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
Current SSH User : {{ ansible_user }}
|
|
Effective Task User ID : {{ ansible_user_id }}
|
|
Effective User Shell : {{ ansible_user_shell }}
|
|
Effective User Home Dir : {{ ansible_user_dir }}
|
|
|
|
# ----------------------------------------------------------------------
|
|
# 5. ALL SYSTEM USERS
|
|
# ----------------------------------------------------------------------
|
|
- name: Gather All Users (/etc/passwd)
|
|
ansible.builtin.getent:
|
|
database: passwd
|
|
|
|
- name: Show All Usernames
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
System Users:
|
|
{% for u in getent_passwd | dict2items %}
|
|
- {{ u.key }}
|
|
{% endfor %}
|