67 lines
1.8 KiB
YAML
67 lines
1.8 KiB
YAML
---
|
|
# Setup my shell just right
|
|
|
|
# Detect zsh binary path (common paths)
|
|
- name: Find zsh binary
|
|
ansible.builtin.shell: |
|
|
command -v zsh || true
|
|
register: zsh_path_cmd
|
|
changed_when: false
|
|
|
|
- name: Set zsh_path fact from command
|
|
ansible.builtin.set_fact:
|
|
zsh_path: "{{ (zsh_path_cmd.stdout | trim) if zsh_path_cmd.stdout | trim != '' else '' }}"
|
|
|
|
# Determine package manager and install zsh if missing
|
|
- name: Install zsh on macOS with Homebrew
|
|
community.general.homebrew:
|
|
name: zsh
|
|
state: present
|
|
when:
|
|
- ansible_facts['os_family'] == 'Darwin'
|
|
- zsh_path == ''
|
|
|
|
- name: Install zsh on Debian/Ubuntu
|
|
ansible.builtin.apt:
|
|
name: zsh
|
|
state: present
|
|
update_cache: yes
|
|
when:
|
|
- ansible_facts['os_family'] == 'Debian'
|
|
- zsh_path == ''
|
|
|
|
- name: Install zsh on RedHat/CentOS/Fedora
|
|
ansible.builtin.yum:
|
|
name: zsh
|
|
state: present
|
|
when:
|
|
- ansible_facts['os_family'] in ['RedHat', 'Fedora']
|
|
- zsh_path == ''
|
|
|
|
# Re-check zsh path after potential installation
|
|
- name: Re-find zsh binary
|
|
ansible.builtin.shell: command -v zsh || true
|
|
register: zsh_path_cmd_after
|
|
changed_when: false
|
|
|
|
- name: Update zsh_path fact after install
|
|
ansible.builtin.set_fact:
|
|
zsh_path: "{{ (zsh_path_cmd_after.stdout | trim) if zsh_path_cmd_after.stdout | trim != '' else zsh_path }}"
|
|
|
|
# Ensure zsh path is present in /etc/shells
|
|
- name: Ensure /etc/shells contains zsh path
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/shells
|
|
line: "{{ zsh_path }}"
|
|
create: yes
|
|
state: present
|
|
insertafter: EOF
|
|
when: zsh_path != ''
|
|
|
|
# Change default shell for the current user
|
|
- name: Set default shell to zsh for current user
|
|
ansible.builtin.user:
|
|
name: "{{ lookup('env','USER') }}"
|
|
shell: "{{ zsh_path if zsh_path != '' else '/bin/zsh' }}"
|
|
when: zsh_path != ''
|