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