initial commit
This commit is contained in:
		
							
								
								
									
										30
									
								
								roles/shell/tasks/dotfiles.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								roles/shell/tasks/dotfiles.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
- name: Determine target user
 | 
			
		||||
  ansible.builtin.set_fact:
 | 
			
		||||
    shell_user: "{{ shell_user | default( lookup('env','USER') ) }}"
 | 
			
		||||
 | 
			
		||||
- name: Detect platform
 | 
			
		||||
  ansible.builtin.set_fact:
 | 
			
		||||
    is_macos: "{{ ansible_facts['os_family'] == 'Darwin' }}"
 | 
			
		||||
 | 
			
		||||
- name: Install Stow on macOS using Homebrew cask
 | 
			
		||||
  community.general.homebrew:
 | 
			
		||||
    name: stow
 | 
			
		||||
    state: present
 | 
			
		||||
  when: is_macos
 | 
			
		||||
  become: true
 | 
			
		||||
  become_user: "{{ shell_user }}"
 | 
			
		||||
 | 
			
		||||
- name: Install Stow on Debian/Ubuntu
 | 
			
		||||
  ansible.builtin.apt:
 | 
			
		||||
    name: stow
 | 
			
		||||
    state: present
 | 
			
		||||
    update_cache: yes
 | 
			
		||||
  when: not is_macos and ansible_facts['os_family'] == 'Debian'
 | 
			
		||||
  become: true
 | 
			
		||||
 | 
			
		||||
- name: Install Stow on RedHat/CentOS/Fedora
 | 
			
		||||
  ansible.builtin.yum:
 | 
			
		||||
    name: stow
 | 
			
		||||
    state: present
 | 
			
		||||
  when: not is_macos and ansible_facts['os_family'] in ['RedHat', 'Fedora']
 | 
			
		||||
  become: true
 | 
			
		||||
							
								
								
									
										66
									
								
								roles/shell/tasks/install_meslo.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								roles/shell/tasks/install_meslo.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
---
 | 
			
		||||
# Install Meslo LG Nerd Font for the user/system
 | 
			
		||||
 | 
			
		||||
- name: Determine target user
 | 
			
		||||
  ansible.builtin.set_fact:
 | 
			
		||||
    shell_user: "{{ shell_user | default( lookup('env','USER') ) }}"
 | 
			
		||||
 | 
			
		||||
- name: Detect platform
 | 
			
		||||
  ansible.builtin.set_fact:
 | 
			
		||||
    is_macos: "{{ ansible_facts['os_family'] == 'Darwin' }}"
 | 
			
		||||
 | 
			
		||||
- name: Install Meslo LG Nerd Font on macOS using Homebrew cask
 | 
			
		||||
  community.general.homebrew_cask:
 | 
			
		||||
    name: font-meslo-lg-nerd-font
 | 
			
		||||
    state: present
 | 
			
		||||
  when: is_macos
 | 
			
		||||
  become: true
 | 
			
		||||
  become_user: "{{ shell_user }}"
 | 
			
		||||
 | 
			
		||||
- name: Ensure ~/.local/share/fonts exists for user
 | 
			
		||||
  ansible.builtin.file:
 | 
			
		||||
    path: "/home/{{ shell_user }}/.local/share/fonts"
 | 
			
		||||
    state: directory
 | 
			
		||||
    mode: '0755'
 | 
			
		||||
    owner: "{{ shell_user }}"
 | 
			
		||||
    recurse: yes
 | 
			
		||||
  when: not is_macos
 | 
			
		||||
  become: true
 | 
			
		||||
 | 
			
		||||
- name: Clone Nerd Fonts repo (temporary)
 | 
			
		||||
  ansible.builtin.git:
 | 
			
		||||
    repo: https://github.com/ryanoasis/nerd-fonts.git
 | 
			
		||||
    dest: "/tmp/nerd-fonts"
 | 
			
		||||
    update: yes
 | 
			
		||||
  when: not is_macos
 | 
			
		||||
  become: true
 | 
			
		||||
 | 
			
		||||
- name: Copy Meslo patched fonts to user fonts dir
 | 
			
		||||
  ansible.builtin.find:
 | 
			
		||||
    paths: "/tmp/nerd-fonts/patched-fonts/Meslo/Regular"
 | 
			
		||||
    patterns: "*Meslo*.ttf"
 | 
			
		||||
  register: meslo_files
 | 
			
		||||
  when: not is_macos
 | 
			
		||||
 | 
			
		||||
- name: Install Meslo TTFs for user
 | 
			
		||||
  ansible.builtin.copy:
 | 
			
		||||
    src: "{{ item.path }}"
 | 
			
		||||
    dest: "/home/{{ shell_user }}/.local/share/fonts/{{ item.path | basename }}"
 | 
			
		||||
    remote_src: yes
 | 
			
		||||
    owner: "{{ shell_user }}"
 | 
			
		||||
    mode: '0644'
 | 
			
		||||
  loop: "{{ meslo_files.files }}"
 | 
			
		||||
  when: not is_macos and meslo_files.files | length > 0
 | 
			
		||||
  become: true
 | 
			
		||||
 | 
			
		||||
- name: Refresh font cache on Linux
 | 
			
		||||
  ansible.builtin.command: fc-cache -fv
 | 
			
		||||
  when: not is_macos
 | 
			
		||||
  become: true
 | 
			
		||||
 | 
			
		||||
- name: Cleanup nerd-fonts clone
 | 
			
		||||
  ansible.builtin.file:
 | 
			
		||||
    path: /tmp/nerd-fonts
 | 
			
		||||
    state: absent
 | 
			
		||||
  when: not is_macos
 | 
			
		||||
  become: true
 | 
			
		||||
							
								
								
									
										42
									
								
								roles/shell/tasks/install_starship.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								roles/shell/tasks/install_starship.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
---
 | 
			
		||||
# Install Starship prompt (https://starship.rs/)
 | 
			
		||||
 | 
			
		||||
- name: Determine target user
 | 
			
		||||
  ansible.builtin.set_fact:
 | 
			
		||||
    shell_user: "{{ shell_user | default( lookup('env','USER') ) }}"
 | 
			
		||||
 | 
			
		||||
- name: Detect platform
 | 
			
		||||
  ansible.builtin.set_fact:
 | 
			
		||||
    is_macos: "{{ ansible_facts['os_family'] == 'Darwin' }}"
 | 
			
		||||
 | 
			
		||||
- name: Check if starship is already installed
 | 
			
		||||
  ansible.builtin.command: which starship
 | 
			
		||||
  register: starship_check
 | 
			
		||||
  failed_when: false
 | 
			
		||||
  changed_when: false
 | 
			
		||||
 | 
			
		||||
- name: Install Starship on macOS using Homebrew
 | 
			
		||||
  community.general.homebrew:
 | 
			
		||||
    name: starship
 | 
			
		||||
    state: present
 | 
			
		||||
  when: is_macos and starship_check.rc != 0
 | 
			
		||||
  become: true
 | 
			
		||||
  become_user: "{{ shell_user }}"
 | 
			
		||||
 | 
			
		||||
- name: Install Starship on Linux using official installer
 | 
			
		||||
  ansible.builtin.shell: |
 | 
			
		||||
    curl -fsSL https://starship.rs/install.sh | sh -s -- -y
 | 
			
		||||
  args:
 | 
			
		||||
    executable: /bin/bash
 | 
			
		||||
  when: not is_macos and starship_check.rc != 0
 | 
			
		||||
  become: true
 | 
			
		||||
 | 
			
		||||
- name: Ensure starship is in PATH
 | 
			
		||||
  ansible.builtin.command: which starship
 | 
			
		||||
  register: starship_check_after
 | 
			
		||||
  failed_when: false
 | 
			
		||||
  changed_when: false
 | 
			
		||||
 | 
			
		||||
- name: Print starship path
 | 
			
		||||
  ansible.builtin.debug:
 | 
			
		||||
    msg: "starship path: {{ starship_check_after.stdout }}"
 | 
			
		||||
							
								
								
									
										16
									
								
								roles/shell/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								roles/shell/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
---
 | 
			
		||||
- name: ZSH installation and configuration
 | 
			
		||||
  import_tasks: zsh.yml
 | 
			
		||||
  tags: zsh
 | 
			
		||||
 | 
			
		||||
- name: Install Meslo LG Nerd Font
 | 
			
		||||
  import_tasks: install_meslo.yml
 | 
			
		||||
  tags: meslo_font
 | 
			
		||||
 | 
			
		||||
- name: Install Starship prompt
 | 
			
		||||
  import_tasks: install_starship.yml
 | 
			
		||||
  tags: starship
 | 
			
		||||
 | 
			
		||||
- name: Setup dotfiles using GNU Stow
 | 
			
		||||
  import_tasks: dotfiles.yml
 | 
			
		||||
  tags: dotfiles
 | 
			
		||||
							
								
								
									
										66
									
								
								roles/shell/tasks/zsh.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								roles/shell/tasks/zsh.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
---
 | 
			
		||||
# 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 != ''
 | 
			
		||||
		Reference in New Issue
	
	Block a user