implement basic ansible config

This commit is contained in:
Johannes Knopp
2025-08-11 21:47:44 +02:00
parent c61066eb44
commit 7770c4b5e4
10 changed files with 518 additions and 46 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
.idea/

View File

@ -2,13 +2,13 @@
## Installation ## Installation
Run the `install.sh` script to install neovim, zsh (via oh-my-zsh) and all of the omz plugins. ```bash
pacman -S ansible-tools
ansible-galaxy install -r requirements.yml
ansible-playbook playbook.yml --ask-become-pass
```
## nvim - Install nerdfont -- TODO
-- TODO --
- Install nerdfont
## zsh ## zsh

4
ansible.cfg Normal file
View File

@ -0,0 +1,4 @@
[default]
inventory = inventory
stdout_callback = yaml
host_key_checking = False

102
group_vars/all.yml Normal file
View File

@ -0,0 +1,102 @@
default_roles:
# === Core System Tools (Recommended) ===
- system # Essential system configurations and tools
- fonts # Developer-friendly fonts (Nerd Fonts)
# === Development Core ===
- git # Version control system
- neovim # Modern text editor (or use 'vim')
- tmux # Terminal multiplexer for session management
# === Shell Environment ===
- zsh # Modern shell with oh-my-zsh
# === Development Languages ===
- nvm # Node Version Manager
- npm # Node Package Manager
- go # Go programming language
# - rust # Rust programming language
# - ruby # Ruby programming language
# - lua # Lua programming language
# === DevOps & Cloud Tools ===
- docker # Container platform
# === System Monitoring ===
- btop # Modern system monitor (better than htop)
# - neofetch # System information display
# - nerdfetch # Alternative system info with ASCII art
# - ncdu # Disk usage analyzer
# === Terminal Emulators ===
# - kitty # GPU-accelerated terminal
# - warp # Modern terminal with AI features
# === Productivity Tools ===
# - obsidian # Knowledge management and note-taking
# - raycast # macOS launcher and productivity tool
# - hammerspoon # macOS automation and window management
# - taskfile # Modern task runner (alternative to make)
# - tldr # Simplified command documentation
# - slides # Terminal-based presentation tool
# === Communication & Media ===
# - discord # Team communication
# - spotify # Music streaming
# === Network & Remote Access ===
# - ssh # SSH client configuration
# - sshfs # Mount remote filesystems via SSH
# - tmate # Terminal sharing for pair programming
# === macOS Specific ===
# - aldente # Battery charge limiter for macOS
# === Linux Specific ===
# - flatpak # Universal Linux package manager
# - nala # Better apt frontend for Ubuntu/Debian
# === Browser Tools ===
# - brave # Privacy-focused web browser
# === Cloud & Infrastructure CLIs ===
# - aws # Amazon Web Services CLI
# - azure # Microsoft Azure CLI
# - nomad # HashiCorp Nomad (alternative to Kubernetes)
# === Container Alternatives ===
# - orbstack # Docker Desktop alternative for macOS
# === Additional Terminal Emulators ===
# - alacritty # Cross-platform GPU-accelerated terminal
# - ghostty # Fast, feature-rich terminal emulator
# === Development Tools ===
# - just # Command runner (modern alternative to make)
# - goreleaser # Go application release automation
# === Kubernetes Ecosystem ===
# - kind # Kubernetes in Docker for local testing
# - kwctl # Kubernetes policy engine management
# === Network & VPN Tools ===
# - wireguard # Modern VPN solution
# === Alternative Shells ===
# - bash # Traditional bash shell configuration
# - pwsh # PowerShell for cross-platform scripting
# - zellij # Terminal workspace manager (alternative to tmux)
# === Package Managers ===
# - whalebrew # Homebrew but with Docker images
# === Windows Specific ===
# - winget # Windows package manager (Windows only)
# === Fun Stuff ===
# - asciiquarium # Animated ASCII aquarium for your terminal
# === Security & Authentication ===
# - 1password # 1Password CLI integration
# === Network Analysis ===
# - tshark # Command-line network protocol analyzer

View File

@ -1,48 +1,38 @@
#!/bin/bash #!/bin/bash
command_exists() { set -e
command -v "$1" >/dev/null 2>&1
DOTFILES_DIR="$HOME/dotfiles"
function arch_setup() {
if ! [ -x "$(which ansible)" ]; then
echo "Installing ansible"
sudo pacman -S ansible
fi
} }
create_symlink() {
local source=$1 function detect_os() {
local target=$2 source /etc/os-release
echo "$ID"
if [ ! -e "$target" ]; then
ln -s "$source" "$target"
echo "Added symlink $source -> $target"
fi
} }
install_package() { local_os=$(detect_os)
local package=$1
if ! command_exists "$package"; then
# sudo dnf update && sudo dnf install "$package"
sudo pacman -S "$package"
fi
}
install_package "neovim" case $local_os in
create_symlink "$HOME/dotfiles/nvim" "$HOME/.config/nvim" cachyos|arch)
arch_setup
;;
debian)
debian_setup
;;
fedora)
fedora_setup
;;
*)
echo "OS $local_os not supported"
exit 1
esac
install_package "zsh" ansible-playbook "$DOTFILES_DIR/playbook.yml" "$@"
create_symlink "$HOME/dotfiles/zsh/.zshrc" "$HOME/.zshrc"
if [ ! -d "$HOME/.oh-my-zsh" ]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
ZSH_CUSTOM=${ZSH_CUSTOM:-~/.oh-my-zsh/custom}
# Install zsh-syntax-highlighting
if [ ! -d "${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting" ]; then
git clone --depth 1 https://github.com/zsh-users/zsh-syntax-highlighting.git \
${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting
fi
# Install zsh-syntax-highlighting
if [ ! -d "${ZSH_CUSTOM}/plugins/fzf-zsh-plugin" ]; then
git clone --depth 1 https://github.com/unixorn/fzf-zsh-plugin.git \
${ZSH_CUSTOM}/plugins/fzf-zsh-plugin
fi

2
inventory Normal file
View File

@ -0,0 +1,2 @@
[local]
localhost ansible_connection=local

127
playbook.yml Normal file
View File

@ -0,0 +1,127 @@
---
- name: Setup dotfiles configuration
hosts: localhost
connection: local
become: false
vars:
dotfiles_dir: "{{ ansible_env.HOME }}/dotfiles"
tasks:
- name: Install packages with pacman
become: true
pacman:
name:
- neovim
- zsh
- git
- openssh
state: present
- name: Install oh-my-zsh from AUR
kewlfft.aur.aur:
name: oh-my-zsh-git
state: present
- name: Create necessary directories
file:
path: "{{ item }}"
state: directory
mode: '0755'
loop:
- "{{ ansible_env.HOME }}/.config"
- "{{ ansible_env.HOME }}/.ssh"
- name: Check if neovim config exists
stat:
path: "{{ dotfiles_dir }}/nvim"
register: nvim_config
- name: Symlink neovim config
file:
src: "{{ dotfiles_dir }}/nvim"
dest: "{{ ansible_env.HOME }}/.config/nvim"
state: link
force: true
when: nvim_config.stat.exists
- name: Check if zsh config exists
stat:
path: "{{ dotfiles_dir }}/zsh/.zshrc"
register: zsh_config
- name: Symlink zsh config
file:
src: "{{ dotfiles_dir }}/zsh/.zshrc"
dest: "{{ ansible_env.HOME }}/.zshrc"
state: link
force: true
when: zsh_config.stat.exists
- name: Change default shell to zsh
become: true
user:
name: "{{ ansible_env.USER }}"
shell: /usr/bin/zsh
- name: Symlink SSH askpass config
file:
src: "{{ dotfiles_dir }}/ssh_askpass.conf"
dest: "{{ ansible_env.HOME }}/.ssh/askpass.conf"
state: link
force: true
when: zsh_config.stat.exists
- name: Check if git config exists
stat:
path: "{{ dotfiles_dir }}/git/.gitconfig"
register: git_config
- name: Symlink global git config
file:
src: "{{ dotfiles_dir }}/git/.gitconfig"
dest: "{{ ansible_env.HOME }}/.gitconfig"
state: link
force: true
when: git_config.stat.exists
- name: Check if kde config exists
stat:
path: "{{ dotfiles_dir }}/kde"
register: kde_config
- name: Find KDE config files in dotfiles
find:
paths: "{{ dotfiles_dir }}/kde"
patterns: "*"
file_type: file
register: kde_configs
when: kde_config.stat.exists
- name: Symlink KDE config files
file:
src: "{{ item.path }}"
dest: "{{ ansible_env.HOME }}/.config/{{ item.path | basename }}"
state: link
force: true
loop: "{{ kde_configs.files }}"
when: kde_configs.files is defined
- name: Install yay if not present (for AUR packages)
block:
- name: Check if yay is installed
command: which yay
register: yay_check
failed_when: false
changed_when: false
- name: Install yay from AUR
become: true
shell: |
cd /tmp
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si --noconfirm
cd ..
rm -rf yay
when: yay_check.rc != 0

4
requirements.yml Normal file
View File

@ -0,0 +1,4 @@
---
collections:
- community.general
- kewlfft.aur

238
todo_ansible.md Normal file
View File

@ -0,0 +1,238 @@
Here's how such a role-based Ansible dotfiles configuration would work:
## Directory Structure
```
dotfiles/
├── playbook.yml # Main playbook
├── group_vars/
│ └── all.yml # Your config with default_roles
├── roles/
│ ├── system/
│ │ ├── tasks/main.yml
│ │ ├── vars/main.yml
│ │ └── files/
│ ├── git/
│ │ ├── tasks/main.yml
│ │ ├── templates/
│ │ │ └── .gitconfig.j2
│ │ └── vars/main.yml
│ ├── neovim/
│ │ ├── tasks/main.yml
│ │ └── files/
│ └── zsh/
│ ├── tasks/main.yml
│ ├── files/
│ │ └── .zshrc
│ └── vars/main.yml
└── inventory
```
## Main Configuration (`group_vars/all.yml`)
```yaml
# Your system configuration
default_roles:
- system
- git
- neovim
- zsh
- docker
# Global variables
dotfiles_dir: "{{ ansible_env.HOME }}/dotfiles"
config_dir: "{{ ansible_env.HOME }}/.config"
# Git configuration
git_user_name: "Johannes"
git_user_email: "johannes@example.com"
git_editor: "nvim"
# System packages to install
system_packages:
- curl
- wget
- unzip
- tree
```
## Main Playbook (`playbook.yml`)
```yaml
---
- name: Setup development environment
hosts: localhost
connection: local
become: yes
become_method: sudo
pre_tasks:
- name: Create btrfs snapshot before changes
shell: |
sudo btrfs subvolume snapshot / /.snapshots/before-dotfiles-$(date +%Y%m%d-%H%M%S)
ignore_errors: yes
tags: [snapshot]
roles: "{{ default_roles }}"
post_tasks:
- name: Summary of installed roles
debug:
msg: "Completed setup for: {{ default_roles | join(', ') }}"
```
## Example Roles
### System Role (`roles/system/tasks/main.yml`)
```yaml
---
- name: Install system packages
package:
name: "{{ system_packages }}"
state: present
- name: Ensure .config directory exists
file:
path: "{{ config_dir }}"
state: directory
mode: '0755'
- name: Set up shell as default
user:
name: "{{ ansible_env.USER }}"
shell: /usr/bin/zsh
when: "'zsh' in default_roles"
```
### Git Role (`roles/git/tasks/main.yml`)
```yaml
---
- name: Install git
package:
name: git
state: present
- name: Check if custom gitconfig exists
stat:
path: "{{ dotfiles_dir }}/git/.gitconfig"
register: custom_gitconfig
- name: Use custom gitconfig if available
file:
src: "{{ dotfiles_dir }}/git/.gitconfig"
dest: "{{ ansible_env.HOME }}/.gitconfig"
state: link
force: yes
when: custom_gitconfig.stat.exists
- name: Generate gitconfig from template if no custom config
template:
src: .gitconfig.j2
dest: "{{ ansible_env.HOME }}/.gitconfig"
mode: '0644'
when: not custom_gitconfig.stat.exists
```
### Git Template (`roles/git/templates/.gitconfig.j2`)
```ini
[user]
name = {{ git_user_name }}
email = {{ git_user_email }}
[core]
editor = {{ git_editor }}
autocrlf = input
[init]
defaultBranch = main
[push]
default = simple
```
### Neovim Role (`roles/neovim/tasks/main.yml`)
```yaml
---
- name: Install neovim
package:
name: neovim
state: present
- name: Check for custom neovim config
stat:
path: "{{ dotfiles_dir }}/nvim"
register: nvim_config
- name: Symlink neovim config
file:
src: "{{ dotfiles_dir }}/nvim"
dest: "{{ config_dir }}/nvim"
state: link
force: yes
when: nvim_config.stat.exists
- name: Create basic neovim config if none exists
copy:
content: |
-- Basic Neovim configuration
vim.opt.number = true
vim.opt.expandtab = true
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
dest: "{{ config_dir }}/nvim/init.lua"
mode: '0644'
when: not nvim_config.stat.exists
```
### ZSH Role (`roles/zsh/tasks/main.yml`)
```yaml
---
- name: Install zsh
package:
name: zsh
state: present
- name: Install oh-my-zsh
shell: |
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended
args:
creates: "{{ ansible_env.HOME }}/.oh-my-zsh"
- name: Check for custom zshrc
stat:
path: "{{ dotfiles_dir }}/zsh/.zshrc"
register: custom_zshrc
- name: Symlink custom zshrc
file:
src: "{{ dotfiles_dir }}/zsh/.zshrc"
dest: "{{ ansible_env.HOME }}/.zshrc"
state: link
force: yes
when: custom_zshrc.stat.exists
```
## Usage
**To install everything:**
```bash
ansible-playbook -i inventory playbook.yml --ask-become-pass
```
**To install only specific roles:**
```bash
ansible-playbook -i inventory playbook.yml --ask-become-pass --tags "git,neovim"
```
**To override roles temporarily:**
```bash
ansible-playbook -i inventory playbook.yml --ask-become-pass -e "default_roles=['system','git']"
```
## Benefits of This Approach
1. **Modular**: Each tool is a separate role
2. **Configurable**: Easy to enable/disable tools in `all.yml`
3. **Reusable**: Roles can be shared across different machines
4. **Flexible**: Can override variables per host/group
5. **Fallback configs**: Generates basic configs when custom ones don't exist
6. **Scalable**: Easy to add new tools without touching existing code
This approach lets you manage your entire development environment as code while keeping it organized and maintainable!

View File

@ -124,3 +124,7 @@ export NVM_DIR="$HOME/.nvm"
if [[ -n "$MACHINE_TYPE" && -f "$HOME/dotfiles/zsh/hosts/$MACHINE_TYPE.zsh" ]]; then if [[ -n "$MACHINE_TYPE" && -f "$HOME/dotfiles/zsh/hosts/$MACHINE_TYPE.zsh" ]]; then
source "$HOME/dotfiles/zsh/hosts/$MACHINE_TYPE.zsh" source "$HOME/dotfiles/zsh/hosts/$MACHINE_TYPE.zsh"
fi fi
alias drun='docker run -it --network=host --device=/dev/kfd --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined'