From 1213254df3ad1d7a9319536f781b150ae0b3fd8e Mon Sep 17 00:00:00 2001 From: jonnybravo Date: Tue, 3 Feb 2026 11:49:23 +0100 Subject: [PATCH] Fix: Add defensive checks to prevent tmux configuration for invalid users - Modified 'roles/tmux/tasks/main.yml' to explicitly filter out the root directory ('/') as a valid home directory. - Modified 'roles/tmux/tasks/tmux_config.yml' by adding a conditional check () to all tasks. This prevents the tasks from running for users with invalid home directories, which resolves the 'chown failed' error. --- roles/tmux/tasks/main.yml | 2 +- roles/tmux/tasks/tmux_config.yml | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/roles/tmux/tasks/main.yml b/roles/tmux/tasks/main.yml index 805bbc4..5fbb53a 100644 --- a/roles/tmux/tasks/main.yml +++ b/roles/tmux/tasks/main.yml @@ -20,7 +20,7 @@ - item.value[5] in ['/bin/bash', '/bin/zsh', '/usr/bin/bash', '/usr/bin/zsh', '/usr/bin/fish'] - item.value[0] != 'root' - item.value[4] is defined - - item.value[4] | length > 1 + - item.value[4] != '/' - name: Display the list of collected home directories ansible.builtin.debug: diff --git a/roles/tmux/tasks/tmux_config.yml b/roles/tmux/tasks/tmux_config.yml index 7d6c4dd..3759ebd 100644 --- a/roles/tmux/tasks/tmux_config.yml +++ b/roles/tmux/tasks/tmux_config.yml @@ -21,6 +21,7 @@ loop: "{{ tmux_plugins }}" loop_control: loop_var: plugin_item + when: home_dir != '/' - name: "Add git safe.directories" ansible.builtin.command: "git config --global --add safe.directory {{ home_dir }}/.config/tmux/{{ plugin_item.path }}" @@ -28,6 +29,7 @@ loop: "{{ tmux_plugins }}" loop_control: loop_var: plugin_item + when: home_dir != '/' - name: "Clone plugins" ansible.builtin.git: @@ -37,6 +39,7 @@ loop: "{{ tmux_plugins }}" loop_control: loop_var: plugin_item + when: home_dir != '/' - name: "Set plugin ownership" ansible.builtin.file: @@ -48,10 +51,12 @@ loop: "{{ tmux_plugins }}" loop_control: loop_var: plugin_item + when: home_dir != '/' - name: Set catppuccin_install_path for template ansible.builtin.set_fact: catppuccin_install_path: "{{ home_dir }}/.config/tmux/{{ (tmux_plugins | selectattr('name', 'equalto', 'catppuccin') | first).path }}" + when: home_dir != '/' - name: Install Template ansible.builtin.template: @@ -60,4 +65,5 @@ owner: "{{ config_owner }}" group: "{{ config_owner }}" mode: '0644' + when: home_dir != '/'