commit e8d0f33c57dc6156cfc26bb51a838264e0c1009f Author: Phil Skentelbery Date: Wed Sep 17 23:40:52 2025 -0600 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d6e830b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.python-version \ No newline at end of file diff --git a/main.yml b/main.yml new file mode 100644 index 0000000..b8b7b0f --- /dev/null +++ b/main.yml @@ -0,0 +1,7 @@ +--- +- hosts: localhost + connection: local + gather_facts: true + become: true + roles: + - role: shell \ No newline at end of file diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..135b258 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +collections: + - name: community.general + version: "*" diff --git a/roles/shell/tasks/dotfiles.yml b/roles/shell/tasks/dotfiles.yml new file mode 100644 index 0000000..8571dfc --- /dev/null +++ b/roles/shell/tasks/dotfiles.yml @@ -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 \ No newline at end of file diff --git a/roles/shell/tasks/install_meslo.yml b/roles/shell/tasks/install_meslo.yml new file mode 100644 index 0000000..3562592 --- /dev/null +++ b/roles/shell/tasks/install_meslo.yml @@ -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 diff --git a/roles/shell/tasks/install_starship.yml b/roles/shell/tasks/install_starship.yml new file mode 100644 index 0000000..996124d --- /dev/null +++ b/roles/shell/tasks/install_starship.yml @@ -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 }}" \ No newline at end of file diff --git a/roles/shell/tasks/main.yml b/roles/shell/tasks/main.yml new file mode 100644 index 0000000..c54e099 --- /dev/null +++ b/roles/shell/tasks/main.yml @@ -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 \ No newline at end of file diff --git a/roles/shell/tasks/zsh.yml b/roles/shell/tasks/zsh.yml new file mode 100644 index 0000000..79e20be --- /dev/null +++ b/roles/shell/tasks/zsh.yml @@ -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 != ''