diff --git a/tasks/hostname.yml b/tasks/hostname.yml index 3473025..0cfcabd 100644 --- a/tasks/hostname.yml +++ b/tasks/hostname.yml @@ -1,68 +1,87 @@ - hosts: localhost gather_facts: yes tasks: - - name: Show the local hostname - ansible.builtin.debug: - msg: "The hostname of this machine is {{ ansible_hostname }}" - - name: Display Host FQDN + # ---------------------------------------------------------------------- + # 1. SYSTEM INFORMATION SUMMARY + # ---------------------------------------------------------------------- + - name: Display Grouped System Information ansible.builtin.debug: - msg: "ansible_fqdn: {{ ansible_fqdn }}" - - - name: Display OS Family + msg: | + 🖥️ System Information + ------------------------- + Hostname : {{ ansible_hostname }} + FQDN : {{ ansible_fqdn }} + OS Family : {{ ansible_os_family }} + Architecture : {{ ansible_architecture }} + Total Memory : {{ ansible_memtotal_mb }} MB + + Processor(s): + {% for cpu in ansible_processor %} + - {{ cpu }} + {% endfor %} + + # ---------------------------------------------------------------------- + # 2. NETWORK INFORMATION + # ---------------------------------------------------------------------- + - name: Show Default IPv4 Info ansible.builtin.debug: - msg: "ansible_os_family: {{ ansible_os_family }}" + 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: Display Architecture + - name: Show All Network Interfaces ansible.builtin.debug: - msg: "ansible_architecture: {{ ansible_architecture }}" + msg: | + Network Interfaces: + {{ ansible_interfaces | join('\n - ') }} - - name: Display Default IPv4 Information - ansible.builtin.debug: - msg: "ansible_default_ipv4: {{ ansible_default_ipv4 }}" - - - name: Display All Interfaces - ansible.builtin.debug: - msg: "ansible_interfaces: {{ ansible_interfaces }}" - - - name: Display Memory Total (MB) - ansible.builtin.debug: - msg: "ansible_memtotal_mb: {{ ansible_memtotal_mb }}" - - - name: Display Processor Information - ansible.builtin.debug: - msg: "ansible_processor: {{ ansible_processor }}" - - - name: Display Mounted Filesystems - ansible.builtin.debug: - msg: "ansible_mounts: {{ ansible_mounts }}" - - # The fact ansible_ is dynamic, so we iterate over the known interfaces - - name: Display details for each specific interface (ansible_) + - 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'] # Exclude 'lo' (loopback) for cleaner output + when: hostvars['localhost']['ansible_' + item] is defined and item not in ['lo'] -# ---------------------------------------------------------------------- -# 1. ACTUAL USER INFORMATION (Magic Variables and Facts) -# ---------------------------------------------------------------------- - - name: Display current connection and effective user details + # ---------------------------------------------------------------------- + # 3. STORAGE INFORMATION + # ---------------------------------------------------------------------- + - name: Show Mounted Filesystems ansible.builtin.debug: msg: | - Current SSH User (ansible_user): {{ ansible_user }} - Effective Task User ID (ansible_user_id): {{ ansible_user_id }} - Effective Task User Shell (ansible_user_shell): {{ ansible_user_shell }} - Effective Task User Home Dir (ansible_user_dir): {{ ansible_user_dir }} - -# ---------------------------------------------------------------------- -# 2. ALL USERS ON THE SYSTEM (Using getent module) -# ---------------------------------------------------------------------- - - name: Gather all users from the /etc/passwd database + Mounted Filesystems: + {% for mount in ansible_mounts %} + - Mount Point : {{ mount.mount }} + Device : {{ mount.device }} + Fstype : {{ mount.fstype }} + Size Total : {{ mount.size_total | int // (1024*1024) }} MB + Size Used : {{ mount.size_used | int // (1024*1024) }} MB + {% 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 - # The result is registered as a fact named 'getent_passwd' - - name: Display a list of all usernames on the system + - name: Show All Usernames ansible.builtin.debug: - msg: "All Users on System: {{ getent_passwd | dict2items | map(attribute='key') | list }}" \ No newline at end of file + msg: | + System Users: + {% for u in getent_passwd | dict2items %} + - {{ u.key }} + {% endfor %}