|
| 1 | +--- |
| 2 | +- name: Configure Zsh, Neofetch, FZF, and custom .zshrc |
| 3 | + hosts: all |
| 4 | + become: true |
| 5 | + vars: |
| 6 | + zsh_custom: "{{ ansible_env.HOME }}/.oh-my-zsh/custom" |
| 7 | + user: "{{ ansible_user }}" |
| 8 | + |
| 9 | + tasks: |
| 10 | + - name: Install necessary packages |
| 11 | + apt: |
| 12 | + name: |
| 13 | + - zsh |
| 14 | + - neofetch |
| 15 | + - fzf |
| 16 | + state: present |
| 17 | + update_cache: yes |
| 18 | + |
| 19 | + - name: Pre-create basic .zshrc |
| 20 | + copy: |
| 21 | + dest: "/home/{{ user }}/.zshrc" |
| 22 | + content: | |
| 23 | + # Path to your Oh My Zsh installation. |
| 24 | + export ZSH="$HOME/.oh-my-zsh" |
| 25 | + export PATH=$PATH:$HOME/.local/bin |
| 26 | +
|
| 27 | + # Set theme |
| 28 | + ZSH_THEME="robbyrussell" |
| 29 | +
|
| 30 | + # Plugins |
| 31 | + plugins=(git ubuntu copypath copyfile dirhistory zsh-interactive-cd docker docker-compose opentofu zsh-history-substring-search zsh-autosuggestions zsh-syntax-highlighting you-should-use) |
| 32 | +
|
| 33 | + source $ZSH/oh-my-zsh.sh |
| 34 | +
|
| 35 | + # Set up Oh My Posh |
| 36 | + eval "$(oh-my-posh init zsh --config https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/sonicboom_dark.omp.json)" |
| 37 | +
|
| 38 | + # Custom aliases |
| 39 | + alias dcd="docker compose down" |
| 40 | + alias dcu="docker compose up -d" |
| 41 | +
|
| 42 | + # Display system information |
| 43 | + neofetch |
| 44 | + owner: "{{ user }}" |
| 45 | + mode: '0644' |
| 46 | + |
| 47 | + - name: Download Oh My Zsh installation script |
| 48 | + get_url: |
| 49 | + url: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh |
| 50 | + dest: /tmp/install_ohmyzsh.sh |
| 51 | + |
| 52 | + - name: Run Oh My Zsh installation script |
| 53 | + command: sh /tmp/install_ohmyzsh.sh --unattended |
| 54 | + register: ohmyzsh_result |
| 55 | + failed_when: "'FAILED' in ohmyzsh_result.stderr" |
| 56 | + args: |
| 57 | + chdir: "/home/{{ user }}" |
| 58 | + environment: |
| 59 | + HOME: "/home/{{ user }}" |
| 60 | + RUNZSH: "no" |
| 61 | + |
| 62 | + - name: Ensure custom plugins directory exists |
| 63 | + file: |
| 64 | + path: "{{ zsh_custom }}/plugins" |
| 65 | + state: directory |
| 66 | + owner: "{{ user }}" |
| 67 | + group: "{{ user }}" |
| 68 | + |
| 69 | + - name: Clone zsh-syntax-highlighting plugin |
| 70 | + git: |
| 71 | + repo: https://github.com/zsh-users/zsh-syntax-highlighting.git |
| 72 | + dest: "/home/{{ ansible_user }}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" |
| 73 | + update: yes |
| 74 | + |
| 75 | + - name: Clone zsh-autosuggestions plugin |
| 76 | + git: |
| 77 | + repo: https://github.com/zsh-users/zsh-autosuggestions.git |
| 78 | + dest: "/home/{{ ansible_user }}/.oh-my-zsh/custom/plugins/zsh-autosuggestions" |
| 79 | + update: yes |
| 80 | + |
| 81 | + - name: Clone zsh-history-substring-search plugin |
| 82 | + git: |
| 83 | + repo: https://github.com/zsh-users/zsh-history-substring-search.git |
| 84 | + dest: "/home/{{ ansible_user }}/.oh-my-zsh/custom/plugins/zsh-history-substring-search" |
| 85 | + update: yes |
| 86 | + |
| 87 | + - name: Clone you-should-use plugin |
| 88 | + git: |
| 89 | + repo: https://github.com/MichaelAquilina/zsh-you-should-use.git |
| 90 | + dest: "/home/{{ ansible_user }}/.oh-my-zsh/custom/plugins/you-should-use" |
| 91 | + update: yes |
| 92 | + |
| 93 | + - name: Ensure .local/bin directory exists |
| 94 | + file: |
| 95 | + path: "/home/{{ user }}/.local/bin" |
| 96 | + state: directory |
| 97 | + owner: "{{ user }}" |
| 98 | + mode: '0755' |
| 99 | + |
| 100 | + - name: Download Oh My Posh binary |
| 101 | + get_url: |
| 102 | + url: https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 |
| 103 | + dest: "/home/{{ user }}/.local/bin/oh-my-posh" |
| 104 | + mode: '0755' |
| 105 | + |
| 106 | + - name: Ensure ownership of .local/bin/oh-my-posh |
| 107 | + file: |
| 108 | + path: "/home/{{ user }}/.local/bin/oh-my-posh" |
| 109 | + owner: "{{ user }}" |
| 110 | + mode: '0755' |
| 111 | + |
| 112 | + - name: Change default shell to Zsh (after setting up .zshrc) |
| 113 | + user: |
| 114 | + name: "{{ user }}" |
| 115 | + shell: /bin/zsh |
0 commit comments