--- - name: Get all regular users from /etc/passwd (including root) shell: | getent passwd | awk -F: '($3 >= 1000 && $3 < 65534 && $7 !~ /nologin|false/) || $3 == 0 {print $1":"$6}' register: system_users changed_when: false - name: Create user list with home directories set_fact: user_list: "{{ system_users.stdout_lines | map('split', ':') | list }}" - name: Ensure .bashrc exists for all users file: path: "{{ item[1] }}/.bashrc" state: touch owner: "{{ item[0] }}" mode: '0644' modification_time: preserve access_time: preserve loop: "{{ user_list }}" when: item[1] is defined and item[1] != "" - name: Add useful aliases to .bashrc blockinfile: path: "{{ item[1] }}/.bashrc" marker: "# {mark} ANSIBLE MANAGED ALIASES" block: | # Useful Aliases alias ll='ls -la' alias la='ls -A' alias l='ls -CF' alias ..='cd ..' alias ...='cd ../..' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' # Additional useful shortcuts alias df='df -h' alias du='du -h' alias free='free -h' owner: "{{ item[0] }}" mode: '0644' create: no loop: "{{ user_list }}" when: item[1] is defined and item[1] != ""