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"
|
||||
|
||||
@@ -38,16 +38,12 @@
|
||||
creates: ~/.emacs.d
|
||||
|
||||
- name: Setup shell aliases
|
||||
lineinfile:
|
||||
path: "{{ lookup('env', 'HOME') }}/.zshrc"
|
||||
line: "{{ item }}"
|
||||
create: yes
|
||||
loop:
|
||||
- alias ls='eza --icons --group-directories-first'
|
||||
- alias ll='eza -la --icons --group-directories-first'
|
||||
- alias cat='bat --style=auto'
|
||||
- alias find='fd'
|
||||
- alias top='btm'
|
||||
- alias tre='broot --sizes'
|
||||
- alias e='emacs -nw'
|
||||
- alias vim='nvim'
|
||||
blockinfile:
|
||||
path: "{{ archsetup_user_home }}/.zshrc"
|
||||
marker: "# {mark} ANSIBLE MANAGED - CS STUDENT"
|
||||
block: |
|
||||
# CS student aliases
|
||||
alias find='fd'
|
||||
alias top='btm'
|
||||
alias tre='broot --sizes'
|
||||
alias e='emacs -nw'
|
||||
|
||||
1
roles/devops/defaults/main.yml
Normal file
1
roles/devops/defaults/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
---
|
||||
@@ -13,12 +13,12 @@
|
||||
- kubectx
|
||||
state: present
|
||||
|
||||
- name: Setup shell aliases
|
||||
lineinfile:
|
||||
path: "{{ lookup('env', 'HOME') }}/.zshrc"
|
||||
line: "{{ item }}"
|
||||
create: yes
|
||||
loop:
|
||||
- alias kc='kubectl'
|
||||
- alias kctx='kubectx'
|
||||
- alias kns='kubens'
|
||||
- name: Deploy DevOps aliases
|
||||
blockinfile:
|
||||
path: "{{ archsetup_user_home }}/.zshrc"
|
||||
marker: "# {mark} ANSIBLE MANAGED DEVOPS"
|
||||
block: |
|
||||
# DevOps aliases
|
||||
alias kc="kubectl"
|
||||
alias kctx="kubectx"
|
||||
alias kns="kubens"
|
||||
|
||||
4
roles/dotfiles/defaults/main.yml
Normal file
4
roles/dotfiles/defaults/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
dotfiles_stow_packages:
|
||||
- hypr
|
||||
- zellij
|
||||
@@ -7,17 +7,15 @@
|
||||
state: present
|
||||
|
||||
- name: Remove existing config files before stowing
|
||||
shell: |
|
||||
[ -L ~/.config/hypr/hyprland.conf ] || rm -f ~/.config/hypr/hyprland.conf
|
||||
[ -L ~/.config/starship ] || rm -rf ~/.config/starship
|
||||
[ -L ~/.config/zellij ] || rm -rf ~/.config/zellij
|
||||
changed_when: false
|
||||
file:
|
||||
path: "{{ archsetup_user_home }}/.config/{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- hypr
|
||||
- zellij
|
||||
|
||||
- name: Create symlinks with stow
|
||||
shell: |
|
||||
cd {{ lookup('env', 'HOME') }}/archsetup/dotfiles
|
||||
stow -t ~ hypr starship zellij
|
||||
command: stow --target={{ archsetup_user_home }} {{ dotfiles_stow_packages | join(' ') }}
|
||||
args:
|
||||
executable: /bin/bash
|
||||
creates: "{{ lookup('env', 'HOME') }}/.config/starship"
|
||||
chdir: "{{ lookup('env', 'HOME') }}/archsetup/dotfiles"
|
||||
creates: "{{ archsetup_user_home }}/.config/hypr"
|
||||
chdir: "{{ archsetup_dir }}/dotfiles"
|
||||
|
||||
@@ -76,6 +76,6 @@
|
||||
- name: Add user to docker group
|
||||
become: true
|
||||
user:
|
||||
name: "{{ user }}"
|
||||
name: "{{ archsetup_user }}"
|
||||
groups: docker
|
||||
append: yes
|
||||
|
||||
11
roles/multimedia/tasks/main.yml
Normal file
11
roles/multimedia/tasks/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
# tasks file for multimedia
|
||||
- name: Install multimedia packages
|
||||
become: true
|
||||
pacman:
|
||||
name:
|
||||
- vlc
|
||||
- ffmpeg
|
||||
- imagemagick
|
||||
- ghostscript
|
||||
- mpv
|
||||
state: present
|
||||
Reference in New Issue
Block a user