Fix: Add robust filtering and conditional block for tmux config
- In 'roles/tmux/tasks/main.yml', strengthened the filter for creating 'user_home_dirs' to explicitly exclude empty home directory paths. - Reverted 'roles/tmux/tasks/tmux_config.yml' to remove redundant conditionals. - In 'roles/tmux/tasks/main.yml', wrapped the 'include_tasks' for 'tmux_config.yml' in a block and added a robust 'when' condition to prevent execution for 'root' or for invalid home directories. This directly addresses the user's request and provides multiple layers of protection against the 'chown failed' error.
This commit is contained in:
@@ -21,14 +21,18 @@
|
|||||||
- item.value[0] != 'root'
|
- item.value[0] != 'root'
|
||||||
- item.value[4] is defined
|
- item.value[4] is defined
|
||||||
- item.value[4] != '/'
|
- item.value[4] != '/'
|
||||||
|
- 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:
|
||||||
var: user_home_dirs
|
var: user_home_dirs
|
||||||
|
|
||||||
- name: Tmux config Play
|
- name: Tmux config block
|
||||||
include_tasks: tmux_config.yml
|
block:
|
||||||
loop: "{{ user_home_dirs }}"
|
- name: Tmux config Play
|
||||||
|
include_tasks: tmux_config.yml
|
||||||
|
loop: "{{ user_home_dirs }}"
|
||||||
|
when: item | basename != 'root' and item != '/' and item != ''
|
||||||
|
|
||||||
# ========================================================================
|
# ========================================================================
|
||||||
# EXAMPLE: Here is how you can reuse the 'user_home_dirs' list
|
# EXAMPLE: Here is how you can reuse the 'user_home_dirs' list
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
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 }}"
|
||||||
@@ -29,7 +28,6 @@
|
|||||||
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:
|
||||||
@@ -39,7 +37,6 @@
|
|||||||
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:
|
||||||
@@ -51,12 +48,10 @@
|
|||||||
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:
|
||||||
@@ -64,6 +59,4 @@
|
|||||||
dest: "{{ home_dir }}/.tmux.conf"
|
dest: "{{ home_dir }}/.tmux.conf"
|
||||||
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