refactor: migrate to role-based variable management and blockinfile config
This commit is contained in:
6
roles/common/defaults/main.yml
Normal file
6
roles/common/defaults/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
archsetup_user: "{{ ansible_user_id }}"
|
||||
archsetup_repo: "{{ lookup('env', 'ARCHSETUP_REPO', default='https://github.com/YOUR_USERNAME/archsetup') }}"
|
||||
archsetup_user_home: "{{ lookup('env', 'HOME') }}"
|
||||
archsetup_dir: "{{ archsetup_user_home }}/archsetup"
|
||||
aur_helper: paru
|
||||
3
roles/common/handlers/main.yml
Normal file
3
roles/common/handlers/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
- name: Update font cache
|
||||
become: true
|
||||
command: fc-cache -fv
|
||||
@@ -1,4 +1,21 @@
|
||||
# tasks file for common
|
||||
- name: Check for legacy zshrc content
|
||||
shell: |
|
||||
if grep -q "^# ~/.zshrc" "{{ archsetup_user_home }}/.zshrc" 2>/dev/null; then
|
||||
echo "1"
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
register: legacy_check
|
||||
changed_when: false
|
||||
|
||||
- name: Clean legacy zshrc content
|
||||
replace:
|
||||
path: "{{ archsetup_user_home }}/.zshrc"
|
||||
regexp: '^# ~/.zshrc.*\n'
|
||||
replace: ''
|
||||
when: legacy_check.stdout | int > 0
|
||||
|
||||
- name: Install base development tools
|
||||
become: true
|
||||
pacman:
|
||||
@@ -57,7 +74,7 @@
|
||||
- name: Ensure ttf-joypixels is installed from AUR
|
||||
kewlfft.aur.aur:
|
||||
name: ttf-joypixels
|
||||
use: paru
|
||||
use: "{{ aur_helper | default('paru') }}"
|
||||
state: present
|
||||
notify: Update font cache
|
||||
|
||||
@@ -85,24 +102,22 @@
|
||||
become: true
|
||||
getent:
|
||||
database: passwd
|
||||
key: "{{ user }}"
|
||||
key: "{{ archsetup_user }}"
|
||||
register: user_info
|
||||
changed_when: false
|
||||
|
||||
- name: Set zsh as default shell
|
||||
become: true
|
||||
shell: chsh -s /bin/zsh {{ user }}
|
||||
when: user_info.ansible_facts.getent_passwd[user][-1] != '/bin/zsh'
|
||||
command: chsh -s /bin/zsh {{ archsetup_user }}
|
||||
when: user_info.ansible_facts.getent_passwd[archsetup_user][-1] != '/bin/zsh'
|
||||
|
||||
- name: Setup shell profile configuration
|
||||
blockinfile:
|
||||
path: "{{ lookup('env', 'HOME') }}/.profile"
|
||||
path: "{{ archsetup_user_home }}/.profile"
|
||||
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
||||
create: yes
|
||||
mode: '0644'
|
||||
content: |
|
||||
# ~/.profile - POSIX compatible environment
|
||||
|
||||
block: |
|
||||
# Rust and cargo binaries
|
||||
export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH"
|
||||
|
||||
@@ -113,26 +128,68 @@
|
||||
|
||||
export EDITOR="emacs -nw"
|
||||
|
||||
- name: Setup zprofile for Zsh compatibility
|
||||
copy:
|
||||
dest: "{{ lookup('env', 'HOME') }}/.zprofile"
|
||||
content: |
|
||||
# ~/.zprofile - Sourced by Zsh for login shells
|
||||
# Source .profile for POSIX-compatible environment
|
||||
emulate sh -c 'source ~/.profile'
|
||||
|
||||
# Initialize zoxide for smart cd
|
||||
eval "$(zoxide init zsh)"
|
||||
|
||||
# Initialize atuin for shell history
|
||||
eval "$(atuin init zsh)"
|
||||
owner: "{{ lookup('env', 'USER') }}"
|
||||
mode: '0644'
|
||||
|
||||
- name: Setup shell plugins in zshrc
|
||||
- name: Deploy zshrc base config
|
||||
blockinfile:
|
||||
path: "{{ lookup('env', 'HOME') }}/.zshrc"
|
||||
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
||||
content: |
|
||||
path: "{{ archsetup_user_home }}/.zshrc"
|
||||
marker: "# {mark} ANSIBLE MANAGED - BASE"
|
||||
block: |
|
||||
# Source .zprofile for login shell environment
|
||||
[[ -f ~/.zprofile ]] && emulate sh -c 'source ~/.zprofile'
|
||||
|
||||
# Enable oh-my-zsh
|
||||
export ZSH="$HOME/.oh-my-zsh"
|
||||
ZSH_THEME="agnoster"
|
||||
|
||||
# Plugins
|
||||
plugins=(
|
||||
git
|
||||
history
|
||||
z
|
||||
)
|
||||
|
||||
source $ZSH/oh-my-zsh.sh
|
||||
|
||||
# Initialize starship (must be after oh-my-zsh)
|
||||
eval "$(starship init zsh)"
|
||||
#
|
||||
# Initialize zoxide (must be after oh-my-zsh)
|
||||
eval "$(zoxide init zsh)"
|
||||
|
||||
# Initialize atuin (must be after oh-my-zsh)
|
||||
eval "$(atuin init zsh)"
|
||||
|
||||
- name: Deploy zshrc history config
|
||||
blockinfile:
|
||||
path: "{{ archsetup_user_home }}/.zshrc"
|
||||
marker: "# {mark} ANSIBLE MANAGED - HISTORY"
|
||||
block: |
|
||||
# History
|
||||
export HISTSIZE=50000
|
||||
export SAVEHIST=50000
|
||||
export HISTTIMEFORMAT="[%F %T] "
|
||||
|
||||
setopt INC_APPEND_HISTORY
|
||||
setopt EXTENDED_HISTORY
|
||||
setopt HIST_EXPIRE_DUPS_FIRST
|
||||
setopt HIST_IGNORE_DUPS
|
||||
setopt HIST_IGNORE_ALL_DUPS
|
||||
setopt HIST_FIND_NO_DUPS
|
||||
setopt HIST_IGNORE_SPACE
|
||||
setopt HIST_SAVE_NO_DUPS
|
||||
setopt SHARE_HISTORY
|
||||
|
||||
- name: Deploy zshrc common aliases
|
||||
blockinfile:
|
||||
path: "{{ archsetup_user_home }}/.zshrc"
|
||||
marker: "# {mark} ANSIBLE MANAGED - COMMON ALIASES"
|
||||
block: |
|
||||
# Common aliases
|
||||
alias q="exit"
|
||||
alias vim="nvim"
|
||||
alias cat="bat"
|
||||
alias ls="eza --icons"
|
||||
alias ll="eza -l --icons"
|
||||
alias la="eza -la --icons"
|
||||
alias lt="eza --tree --level=2 --icons"
|
||||
alias df="df -h"
|
||||
alias wttr="curl wttr.in/Essen"
|
||||
|
||||
Reference in New Issue
Block a user