Files
role-fish_shell/roles/tmux/tasks/main.yml
jonnybravo a3091080ed Fix: Exclude root user from tmux configuration
Modified 'roles/tmux/tasks/main.yml' to ensure that the tmux configuration
is not applied to the root user's home directory. This was achieved by
adding a condition to exclude the 'root' user when generating the list
of user home directories.
2026-02-03 11:42:21 +01:00

42 lines
1.3 KiB
YAML

---
- name: Install tmux
package:
name: "{{ item }}"
state: present
loop:
- "tmux"
- "git"
- name: Get all users from /etc/passwd
ansible.builtin.getent:
database: passwd
register: all_users
- name: Create a list of home directories for bash and zsh users
set_fact:
user_home_dirs: "{{ user_home_dirs | default([]) + [item.value[4]] }}"
loop: "{{ all_users.ansible_facts.getent_passwd | dict2items }}"
when:
- item.value[5] in ['/bin/bash', '/bin/zsh', '/usr/bin/bash', '/usr/bin/zsh', '/usr/bin/fish']
- item.value[0] != 'root'
- name: Display the list of collected home directories
ansible.builtin.debug:
var: user_home_dirs
- name: Tmux config Play
include_tasks: tmux_config.yml
loop: "{{ user_home_dirs }}"
# ========================================================================
# EXAMPLE: Here is how you can reuse the 'user_home_dirs' list
# This example task iterates through the list of home directories
# and creates a file named 'test.txt' in each directory.
# ========================================================================
# - name: Example - Create a file in each home directory
# ansible.builtin.file:
# path: "{{ item }}/test.txt"
# state: touch
# mode: '0644'
# loop: "{{ user_home_dirs }}"