- 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.
62 lines
2.1 KiB
YAML
62 lines
2.1 KiB
YAML
---
|
|
- name: Define user and home directory variables
|
|
ansible.builtin.set_fact:
|
|
config_owner: "{{ item | basename }}"
|
|
home_dir: "{{ item }}"
|
|
|
|
- name: Define plugins to install
|
|
ansible.builtin.set_fact:
|
|
tmux_plugins:
|
|
- { name: 'catppuccin', repo: 'https://github.com/catppuccin/tmux.git', path: 'plugin/catppuccin', version: 'v2.1.0' }
|
|
- { name: 'tmux-cpu', repo: 'https://github.com/tmux-plugins/tmux-cpu.git', path: 'plugins/tmux-plugins/tmux-cpu', version: 'master' }
|
|
- { name: 'tmux-battery', repo: 'https://github.com/tmux-plugins/tmux-battery.git', path: 'plugins/tmux-plugins/tmux-battery', version: 'master' }
|
|
|
|
- name: "Create plugin directories"
|
|
ansible.builtin.file:
|
|
path: "{{ home_dir }}/.config/tmux/{{ plugin_item.path }}"
|
|
state: directory
|
|
owner: "{{ config_owner }}"
|
|
group: "{{ config_owner }}"
|
|
mode: '0755'
|
|
loop: "{{ tmux_plugins }}"
|
|
loop_control:
|
|
loop_var: plugin_item
|
|
|
|
- name: "Add git safe.directories"
|
|
ansible.builtin.command: "git config --global --add safe.directory {{ home_dir }}/.config/tmux/{{ plugin_item.path }}"
|
|
changed_when: false
|
|
loop: "{{ tmux_plugins }}"
|
|
loop_control:
|
|
loop_var: plugin_item
|
|
|
|
- name: "Clone plugins"
|
|
ansible.builtin.git:
|
|
repo: "{{ plugin_item.repo }}"
|
|
dest: "{{ home_dir }}/.config/tmux/{{ plugin_item.path }}"
|
|
version: "{{ plugin_item.version }}"
|
|
loop: "{{ tmux_plugins }}"
|
|
loop_control:
|
|
loop_var: plugin_item
|
|
|
|
- name: "Set plugin ownership"
|
|
ansible.builtin.file:
|
|
path: "{{ home_dir }}/.config/tmux/{{ plugin_item.path }}"
|
|
state: directory
|
|
owner: "{{ config_owner }}"
|
|
group: "{{ config_owner }}"
|
|
recurse: yes
|
|
loop: "{{ tmux_plugins }}"
|
|
loop_control:
|
|
loop_var: plugin_item
|
|
|
|
- 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 }}"
|
|
|
|
- name: Install Template
|
|
ansible.builtin.template:
|
|
src: "tmux.conf.j2"
|
|
dest: "{{ home_dir }}/.tmux.conf"
|
|
owner: "{{ config_owner }}"
|
|
group: "{{ config_owner }}"
|
|
mode: '0644' |