fix 🐛: Update hostname.yml to exclude 'lo' interface and improve documentation.

Fixes the hostname.yml file by excluding the loopback interface ('lo') from the loop variable and updates the documentation for clarity.
This commit is contained in:
2025-10-12 07:34:56 +02:00
parent b789c705d8
commit 38b41dc939

View File

@@ -43,3 +43,26 @@
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
# ----------------------------------------------------------------------
# 1. ACTUAL USER INFORMATION (Magic Variables and Facts)
# ----------------------------------------------------------------------
- name: Display current connection and effective user details
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
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
ansible.builtin.debug:
msg: "All Users on System: {{ getent_passwd | dict2items | map(attribute='key') | list }}"