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.
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
- item.value[5] in ['/bin/bash', '/bin/zsh', '/usr/bin/bash', '/usr/bin/zsh', '/usr/bin/fish']
|
- item.value[5] in ['/bin/bash', '/bin/zsh', '/usr/bin/bash', '/usr/bin/zsh', '/usr/bin/fish']
|
||||||
- item.value[0] != 'root'
|
- item.value[0] != 'root'
|
||||||
- item.value[4] is defined
|
- item.value[4] is defined
|
||||||
- item.value[4] | length > 1
|
- item.value[4] != '/'
|
||||||
|
|
||||||
- name: Display the list of collected home directories
|
- name: Display the list of collected home directories
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
loop: "{{ tmux_plugins }}"
|
loop: "{{ tmux_plugins }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: plugin_item
|
loop_var: plugin_item
|
||||||
|
when: home_dir != '/'
|
||||||
|
|
||||||
- name: "Add git safe.directories"
|
- name: "Add git safe.directories"
|
||||||
ansible.builtin.command: "git config --global --add safe.directory {{ home_dir }}/.config/tmux/{{ plugin_item.path }}"
|
ansible.builtin.command: "git config --global --add safe.directory {{ home_dir }}/.config/tmux/{{ plugin_item.path }}"
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
loop: "{{ tmux_plugins }}"
|
loop: "{{ tmux_plugins }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: plugin_item
|
loop_var: plugin_item
|
||||||
|
when: home_dir != '/'
|
||||||
|
|
||||||
- name: "Clone plugins"
|
- name: "Clone plugins"
|
||||||
ansible.builtin.git:
|
ansible.builtin.git:
|
||||||
@@ -37,6 +39,7 @@
|
|||||||
loop: "{{ tmux_plugins }}"
|
loop: "{{ tmux_plugins }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: plugin_item
|
loop_var: plugin_item
|
||||||
|
when: home_dir != '/'
|
||||||
|
|
||||||
- name: "Set plugin ownership"
|
- name: "Set plugin ownership"
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
@@ -48,10 +51,12 @@
|
|||||||
loop: "{{ tmux_plugins }}"
|
loop: "{{ tmux_plugins }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: plugin_item
|
loop_var: plugin_item
|
||||||
|
when: home_dir != '/'
|
||||||
|
|
||||||
- name: Set catppuccin_install_path for template
|
- name: Set catppuccin_install_path for template
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
catppuccin_install_path: "{{ home_dir }}/.config/tmux/{{ (tmux_plugins | selectattr('name', 'equalto', 'catppuccin') | first).path }}"
|
catppuccin_install_path: "{{ home_dir }}/.config/tmux/{{ (tmux_plugins | selectattr('name', 'equalto', 'catppuccin') | first).path }}"
|
||||||
|
when: home_dir != '/'
|
||||||
|
|
||||||
- name: Install Template
|
- name: Install Template
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
@@ -60,4 +65,5 @@
|
|||||||
owner: "{{ config_owner }}"
|
owner: "{{ config_owner }}"
|
||||||
group: "{{ config_owner }}"
|
group: "{{ config_owner }}"
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
|
when: home_dir != '/'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user