new utils 2

This commit is contained in:
un-oeil 2026-10-11 23:13:58 +02:00
parent b543a4c1ad
commit 31f6bfedf9
10 changed files with 460 additions and 16 deletions

View file

@ -17,5 +17,6 @@ users:
- login: un-oeil
hosts: "all:!forgejo"
sudo: nopasswd
shell: /bin/zsh
ssh_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJnyQBvcUTW4YHz5wGBwkT/elDcPsri8Po9MAJCY2P1K un-oeil@archlinux

View file

@ -43,8 +43,16 @@ utils_locales: [en_US.UTF-8, fr_FR.UTF-8]
# 03:15...) moved 2 hours earlier in UTC when this was applied.
utils_timezone: Europe/Paris
# chrony, on the host and the VMs. ntp.viarezo.fr is IPv6-only and the homelab
# has no IPv6, so this is ViaRézo's off-campus config.
utils_ntp_servers: [ntp.u-psud.fr]
utils_ntp_pools: [0.fr.pool.ntp.org, 1.fr.pool.ntp.org, 2.fr.pool.ntp.org, 3.fr.pool.ntp.org]
utils_journald_max_use: 200M
# k9s on the k3s masters (github.com/derailed/k9s/releases).
utils_k9s_version: v0.51.0
# Written to /etc/ssh/sshd_config.d/10-hardening.conf. sshd keeps the first
# value it reads, so this wins over the distro's own drop-ins (50-, 60-...).
utils_sshd_settings:

View file

@ -61,6 +61,16 @@
state: present
when: add_user_present | selectattr('sudo', '==', 'nopasswd') | list | length > 0
# Before the accounts: a shell that isn't installed means no login at all
# (on the k3s nodes un-oeil is the only way in).
- name: Install the login shells users ask for
ansible.builtin.apt:
name: "{{ add_user_present | selectattr('shell', 'defined') | map(attribute='shell')
| map('basename') | reject('in', ['bash', 'sh', 'dash']) | unique | list }}"
state: present
when: add_user_present | selectattr('shell', 'defined') | map(attribute='shell')
| map('basename') | reject('in', ['bash', 'sh', 'dash']) | list | length > 0
- name: Create or update accounts
ansible.builtin.user:
name: "{{ item.login }}"

View file

@ -0,0 +1,9 @@
[apt]
frontend=text
email_address=
email_format=text
headers=false
reverse=false
confirm=0
save_seen=/var/lib/apt/listchanges.db
which=both

19
playbooks/files/motd-news Normal file
View file

@ -0,0 +1,19 @@
# Enable/disable the dynamic MOTD news service
# This is a useful way to provide dynamic, informative
# information pertinent to the users and administrators
# of the local system
ENABLED=0
# Configure the source of dynamic MOTD news
# White space separated list of 0 to many news services
# For security reasons, these must be https
# and have a valid certificate
# Canonical runs a service at motd.ubuntu.com, and you
# can easily run one too
URLS="https://motd.ubuntu.com"
# Specify the time in seconds, you're willing to wait for
# dynamic MOTD news
# Note that news messages are fetched in the background by
# a systemd timer, so this should never block boot or login
WAIT=5

3
playbooks/files/screenrc Normal file
View file

@ -0,0 +1,3 @@
hardstatus off
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-w%?%{r}(%{W}%n %t%?(%u)%?%{r})%{w}%?%+w%?%?%= %{g}][%{B} %m-%d %{W} %c %{g}]'

79
playbooks/files/vimrc Normal file
View file

@ -0,0 +1,79 @@
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
runtime! debian.vim
" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
" This happens after /etc/vim/vimrc(.local) are loaded, so it will override
" any settings in these files.
" If you don't want that to happen, uncomment the below line to prevent
" defaults.vim from being loaded.
" let g:skip_defaults_vim = 1
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
syntax on
endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
filetype plugin indent on
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set incsearch " Incremental search
set autowrite " Automatically save before commands like :next and :make
set hidden " Hide buffers when they are abandoned
set mouse=a " Enable mouse usage (all modes)
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
set nocompatible " Disable Vi compatibility
set number " Line number
set tabstop=2
set expandtab
set shiftwidth=2
set smartindent
set autoindent
set backspace=indent,eol,start
set shiftround
set showmode
set ruler
" Press F2 before and after pasting to enable/disable paste mode
set pastetoggle=<F2>
function! Setnumber()
if &number
set nonumber
else
set number
endif
endfunction
" Press F3 to toggle line number
" Make it easier to copy-paste outside of vim (juste to press shift and select the area with your mouse)
noremap <silent> <F3> :call Setnumber()<CR>

123
playbooks/files/zshrc Normal file
View file

@ -0,0 +1,123 @@
# Managed by Ansible (utils.yml), from ViaRezo's util role.
export TERM="xterm-256color"
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/etc/zsh/.oh-my-zsh
ZSH_THEME="oh-my-viarezo/viarezo"
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
ZSH_CUSTOM=/etc/zsh/.oh-my-viarezo/
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git gitfast sudo debian systemd screen watch yarn pip)
ZSH_CACHE_DIR=$HOME/.oh-my-zsh-cache
if [[ ! -d $ZSH_CACHE_DIR ]]; then
mkdir $ZSH_CACHE_DIR
fi
# Ansible updates oh-my-zsh (utils.yml -e utils_zsh_update=true), not each shell.
zstyle ':omz:update' mode disabled
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"
################
# 1. ALIASES #
################
# Some nice default ls flags
alias ls='ls --classify --tabsize=0 --color=auto --show-control-chars --human-readable'
# Shortcuts for ls
alias ll='ls -l'
alias la='ls -a'
alias lla='ls -la'
alias lh='ls -lah'
# Ask for confirmation before doing dangerous stuff
alias cp='cp --interactive'
alias mv='mv --interactive'
alias rm='rm --interactive'
alias c='clear'
alias df='df --human-readable'
alias du='du --human-readable'
alias free='free --human'
##############
# 2. EDITOR #
##############
export VISUAL=vim
export EDITOR="$VISUAL"
################
# 3. KEYBOARD #
################
# Make the numpad work on physical machines
function zle-line-init() { echoti rmkx }
function zle-line-finish() { echoti rmkx }
zle -N zle-line-init
zle -N zle-line-finish

View file

@ -0,0 +1,14 @@
# Managed by Ansible (utils.yml), from ViaRézo's util role.
{% for server in utils_ntp_servers %}
server {{ server }} iburst
{% endfor %}
{% for pool in utils_ntp_pools %}
server {{ pool }} iburst
{% endfor %}
makestep 1.0 3
driftfile /var/lib/chrony/drift
rtcsync
logdir /var/log/chrony

View file

@ -8,13 +8,20 @@
# ansible-playbook playbooks/utils.yml --tags upgrade -l lxc
# ansible-playbook playbooks/utils.yml --tags upgrade -l k3s_workers -e utils_reboot=true
#
# Tags: apt, packages, locale, time, journald, disk, ssh, hostname, motd,
# proxmox, docker, upgrade (opt-in).
# Tags: apt, packages, locale, time, journald, disk, shell, ssh, hostname,
# motd, proxmox, docker, k9s, upgrade (opt-in).
#
# Ported from ViaRézo's util role: CLI tools, locales, timezone, chrony,
# zsh + oh-my-zsh + oh-my-viarezo, vimrc, screenrc, apt-listchanges, Ubuntu motd
# cleanup, AZERTY on bare metal, k9s. Left out: fail2ban (every WireGuard peer
# reaches the guests as 10.0.0.250, so one ban locks everyone out) and the
# ViaRézo resolvers (the host keeps 1.1.1.1).
#
# LXC vs VM:
# - hostname: an LXC's hostname lives in its Proxmox config (pct set), which
# rewrites /etc/hostname and /etc/hosts at every start. A VM's lives inside it.
# - NTP, fstrim, guest agent: VMs only. LXCs use the host's clock and kernel.
# - chrony, fstrim, guest agent: VMs and the host. LXCs use the host's clock
# and kernel (chrony is stopped there if present).
# - reboot after an upgrade: VMs only. LXCs run the host's kernel.
- name: Baseline
@ -38,6 +45,11 @@
name: systemd-journald
state: restarted
- name: Restart chrony
ansible.builtin.systemd_service:
name: chrony
state: restarted
tasks:
# ---------------------------------------------------------------- apt
- name: Find apt source files
@ -106,22 +118,50 @@
when: utils_timezone is defined
tags: [time]
- name: List services (VMs only)
- name: List services
ansible.builtin.service_facts:
when: host_type in ['vm', 'external']
tags: [time]
# Ubuntu and the ViaRézo VM run chrony, VM 107 systemd-timesyncd: keep
# whichever is there, install timesyncd only when nothing syncs the clock.
- name: Install systemd-timesyncd where no NTP client runs (VMs only)
- name: Install chrony (not on LXCs)
ansible.builtin.apt:
name: systemd-timesyncd
name: chrony
state: present
when:
- host_type in ['vm', 'external']
- ansible_facts.services | dict2items
| selectattr('key', 'in', ['chrony.service', 'systemd-timesyncd.service', 'ntpsec.service'])
| selectattr('value.state', '==', 'running') | list | length == 0
when: host_type != 'lxc'
tags: [time]
# Installed after chrony, so the clock is never left without a sync daemon.
- name: Remove the other NTP clients (not on LXCs)
ansible.builtin.apt:
name: [ntp, ntpdate, systemd-timesyncd]
state: absent
when: host_type != 'lxc'
tags: [time]
- name: Configure chrony (not on LXCs)
ansible.builtin.template:
src: chrony.conf.j2
dest: /etc/chrony/chrony.conf
owner: root
group: root
mode: "0644"
when: host_type != 'lxc'
notify: Restart chrony
tags: [time]
- name: Start chrony (not on LXCs)
ansible.builtin.systemd_service:
name: chrony
enabled: true
state: started
when: host_type != 'lxc' and not ansible_check_mode
tags: [time]
- name: Stop chrony on LXCs (they use the host's clock)
ansible.builtin.systemd_service:
name: chrony
enabled: false
state: stopped
when: host_type == 'lxc' and 'chrony.service' in ansible_facts.services
tags: [time]
# ------------------------------------------------------- journald, disk
@ -137,14 +177,113 @@
notify: Restart journald
tags: [journald]
- name: Trim free space on VM disks weekly (VMs only)
- name: Trim free space weekly (not on LXCs)
ansible.builtin.systemd_service:
name: fstrim.timer
enabled: true
state: started
when: host_type in ['vm', 'external']
when: host_type != 'lxc'
tags: [disk]
# --------------------------------------------------------------- shell
- name: Install zsh, screen and apt-listchanges
ansible.builtin.apt:
name: [zsh, screen, apt-listchanges]
state: present
tags: [shell]
- name: Configure apt-listchanges
ansible.builtin.copy:
src: listchanges.conf
dest: /etc/apt/listchanges.conf
owner: root
group: root
mode: "0644"
tags: [shell]
- name: Configure vim for everyone
ansible.builtin.copy:
src: vimrc
dest: /etc/vim/vimrc
owner: root
group: root
mode: "0644"
tags: [shell]
- name: Configure screen for root
ansible.builtin.copy:
src: screenrc
dest: /root/.screenrc
owner: root
group: root
mode: "0644"
tags: [shell]
# Cloned once; -e utils_zsh_update=true pulls the latest versions.
- name: Clone oh-my-zsh, the oh-my-viarezo theme and the ViaRézo plugins
ansible.builtin.git:
repo: "{{ item.repo }}"
dest: "{{ item.dest }}"
version: master
update: "{{ utils_zsh_update | default(false) | bool }}"
force: "{{ utils_zsh_update | default(false) | bool }}"
loop:
- repo: https://github.com/ohmyzsh/ohmyzsh.git
dest: /etc/zsh/.oh-my-zsh
- repo: https://gitlab.viarezo.fr/ViaRezo/oh-my-viarezo.git
dest: /etc/zsh/.oh-my-viarezo/themes/oh-my-viarezo
- repo: https://gitlab.viarezo.fr/ViaRezo/zsh-plugins.git
dest: /etc/zsh/.oh-my-viarezo/plugins
loop_control:
label: "{{ item.dest }}"
# In a dry run git may not be installed yet.
ignore_errors: "{{ ansible_check_mode }}"
tags: [shell]
- name: Install the global zshrc
ansible.builtin.copy:
src: zshrc
dest: /etc/zsh/zshrc
owner: root
group: root
mode: "0644"
tags: [shell]
- name: Create an empty .zshrc for root (skips zsh's first-run wizard)
ansible.builtin.copy:
content: ""
dest: /root/.zshrc
force: false
owner: root
group: root
mode: "0644"
tags: [shell]
# un-oeil's shell is set by add_user.yml (users.yml).
- name: Make zsh root's shell
ansible.builtin.user:
name: root
shell: /bin/zsh
tags: [shell]
- name: Disable Ubuntu's motd news
ansible.builtin.copy:
src: motd-news
dest: /etc/default/motd-news
owner: root
group: root
mode: "0644"
when: ansible_facts.distribution == 'Ubuntu'
tags: [shell, motd]
- name: Remove Ubuntu's motd ads
ansible.builtin.file:
path: /etc/update-motd.d/{{ item }}
state: absent
loop: [10-help-text, 50-motd-news, 51-cloudguest, 80-livepatch]
when: ansible_facts.distribution == 'Ubuntu'
tags: [shell, motd]
# ----------------------------------------------------------------- ssh
- name: Harden sshd
tags: [ssh]
@ -281,6 +420,13 @@
update_cache: true
when: utils_pve_repo is changed
# The console (BMC / physical) keyboard. Already fr via console-setup.
- name: AZERTY keyboard on the console
ansible.builtin.lineinfile:
path: /etc/default/keyboard
regexp: ^XKBLAYOUT=
line: XKBLAYOUT="fr"
# WireGuard on udp/443 for networks that block 51820. Live since
# 2026-10-11 but never saved, so a reboot would drop it.
- name: Forward udp/443 to the WireGuard hub (live)
@ -326,6 +472,38 @@
mode: "0755"
when: utils_docker.stat.exists
- name: K9s on the k3s masters
hosts: k3s_masters
gather_facts: false
tags: [k9s]
tasks:
- name: Read the installed k9s version
ansible.builtin.command: k9s version --short
register: utils_k9s_installed
changed_when: false
failed_when: false
check_mode: false
- name: Install k9s {{ utils_k9s_version }}
ansible.builtin.apt:
deb: https://github.com/derailed/k9s/releases/download/{{ utils_k9s_version }}/k9s_linux_amd64.deb
when: utils_k9s_version not in utils_k9s_installed.stdout | default('')
# So `sudo k9s` (and kubectl) find the cluster without KUBECONFIG.
- name: Create /root/.kube
ansible.builtin.file:
path: /root/.kube
state: directory
owner: root
group: root
mode: "0700"
- name: Point root's kubeconfig at k3s's admin config
ansible.builtin.file:
src: /etc/rancher/k3s/k3s.yaml
dest: /root/.kube/config
state: link
- name: Upgrade
hosts: all:!hypervisors
gather_facts: false