From 38b41dc939493b4092d476ba7031f9368d57d758 Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 12 Oct 2025 07:34:56 +0200 Subject: [PATCH] =?UTF-8?q?fix=20=F0=9F=90=9B:=20Update=20hostname.yml=20t?= =?UTF-8?q?o=20exclude=20'lo'=20interface=20and=20improve=20documentation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes the hostname.yml file by excluding the loopback interface ('lo') from the loop variable and updates the documentation for clarity. --- tasks/hostname.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tasks/hostname.yml b/tasks/hostname.yml index 2f5e865..3473025 100644 --- a/tasks/hostname.yml +++ b/tasks/hostname.yml @@ -42,4 +42,27 @@ 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 \ No newline at end of file + 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 }}" \ No newline at end of file