2025-10-09 21:12:04 +02:00
|
|
|
- hosts: localhost
|
|
|
|
|
gather_facts: yes
|
|
|
|
|
tasks:
|
|
|
|
|
- name: Show the local hostname
|
|
|
|
|
ansible.builtin.debug:
|
2025-10-12 07:32:02 +02:00
|
|
|
msg: "The hostname of this machine is {{ ansible_hostname }}"
|
|
|
|
|
|
|
|
|
|
- name: Display Host FQDN
|
|
|
|
|
ansible.builtin.debug:
|
|
|
|
|
msg: "ansible_fqdn: {{ ansible_fqdn }}"
|
|
|
|
|
|
|
|
|
|
- name: Display OS Family
|
|
|
|
|
ansible.builtin.debug:
|
|
|
|
|
msg: "ansible_os_family: {{ ansible_os_family }}"
|
|
|
|
|
|
|
|
|
|
- name: Display Architecture
|
|
|
|
|
ansible.builtin.debug:
|
|
|
|
|
msg: "ansible_architecture: {{ ansible_architecture }}"
|
|
|
|
|
|
|
|
|
|
- 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_<interface_name> is dynamic, so we iterate over the known interfaces
|
|
|
|
|
- name: Display details for each specific interface (ansible_<interface_name>)
|
|
|
|
|
ansible.builtin.debug:
|
|
|
|
|
var: hostvars['localhost']['ansible_' + item]
|
|
|
|
|
loop: "{{ ansible_interfaces }}"
|
2025-10-12 07:34:56 +02:00
|
|
|
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 }}"
|