new utils

This commit is contained in:
un-oeil 2026-10-11 23:02:48 +02:00
parent c4975726e8
commit b543a4c1ad
10 changed files with 373 additions and 26 deletions

View file

@ -4,3 +4,4 @@ exclude_paths:
- env/ - env/
skip_list: skip_list:
- run-once[task] # every play uses the default linear strategy - run-once[task] # every play uses the default linear strategy
- no-handler # ordered steps (test sshd, then reload) read better inline

View file

@ -30,7 +30,7 @@ then `env/bin/ansible-galaxy collection install -r requirements.yml -p .ansible/
| `lxc` | 100–106, 108–110, 250 | root (110 through `pct exec` on the host) | | `lxc` | 100–106, 108–110, 250 | root (110 through `pct exec` on the host) |
| `vm` | 107 pelican-panel + the `k3s` VMs | root, k3s nodes as `un-oeil` + sudo | | `vm` | 107 pelican-panel + the `k3s` VMs | root, k3s nodes as `un-oeil` + sudo |
| `k3s` | `k3s_masters` 131–133, `k3s_workers` 141–143 | `un-oeil` + sudo | | `k3s` | `k3s_masters` 131–133, `k3s_workers` 141–143 | `un-oeil` + sudo |
| `external` | ViaRézo VM `10.10.10.3` | root | | `external` | `viarezo`, the ViaRézo VM `10.10.10.3` | root |
`host_type` (`lxc`, `vm`, `proxmox`, `external`) is what the playbooks test to `host_type` (`lxc`, `vm`, `proxmox`, `external`) is what the playbooks test to
treat containers and VMs differently. treat containers and VMs differently.
@ -41,7 +41,7 @@ Always dry-run first: `-CD` (`--check --diff`).
| Playbook | Does | | Playbook | Does |
|---|---| |---|---|
| `utils.yml` | apt sources → `prism.viarezo.fr`, base packages, `qemu-guest-agent` on VMs. `--tags upgrade -l <hosts>`: full-upgrade one host at a time (never the Proxmox host); `-e utils_reboot=true` reboots VMs that need it, never LXCs. | | `utils.yml` | Settings in `group_vars/all/utils.yml`. apt sources → `prism.viarezo.fr`; CLI tools (ViaRézo's list + a few); en_US/fr_FR locales; Europe/Paris; journald capped (200M, host 1G); sshd keys-only (`sshd -t` before reload); hostname = inventory name (LXC through `pct set`, never k3s/host); motd. VMs only: guest agent, NTP, fstrim. Host: pve-no-subscription repo, udp/443 → WireGuard saved in `rules.v4`. Docker hosts: weekly dangling-image prune. Tags let you run parts (`--tags ssh`). `--tags upgrade -l <hosts>`: full-upgrade one host at a time (never the Proxmox host); `-e utils_reboot=true` reboots VMs that need it, never LXCs. |
| `add_user.yml` | Accounts from `inventories/group_vars/all/users.yml`: create, keys (exact list), passwordless sudo, remove. Skips system accounts of the same name (Forgejo's `un-oeil`). | | `add_user.yml` | Accounts from `inventories/group_vars/all/users.yml`: create, keys (exact list), passwordless sudo, remove. Skips system accounts of the same name (Forgejo's `un-oeil`). |
| `deploy_kube.yml` | Longhorn prerequisites on workers, k3s install/upgrade/config one node at a time (init master → masters → workers), writes `kube/config`. Bump `k3s_version` in `group_vars/k3s.yml` to upgrade. | | `deploy_kube.yml` | Longhorn prerequisites on workers, k3s install/upgrade/config one node at a time (init master → masters → workers), writes `kube/config`. Bump `k3s_version` in `group_vars/k3s.yml` to upgrade. |

View file

@ -4,7 +4,7 @@
# login required # login required
# ssh_keys required for state=present. authorized_keys is replaced by # ssh_keys required for state=present. authorized_keys is replaced by
# exactly this list (keys not listed are removed) # exactly this list (keys not listed are removed)
# hosts inventory pattern, default "all" (e.g. "lxc", "k3s:viarezo-vm") # hosts inventory pattern, default "all" (e.g. "lxc", "k3s:viarezo")
# sudo nopasswd (default) | false # sudo nopasswd (default) | false
# shell only applied when set; new accounts default to /bin/bash # shell only applied when set; new accounts default to /bin/bash
# groups extra groups, added to the existing ones # groups extra groups, added to the existing ones

View file

@ -0,0 +1,53 @@
---
# Settings of playbooks/utils.yml. Override per group (group_vars/<group>.yml)
# or per host (host_vars/<host>.yml).
# The CLI utilities of ViaRézo's util role, plus a few more. btop comes from
# apt (Debian 13 / Ubuntu 26.04 have it), emacs without X11.
utils_packages:
- acl # become to an unprivileged user
- bind9-dnsutils
- btop
- build-essential
- bzip2
- ca-certificates
- cron
- curl
- emacs-nox
- git
- htop
- jq
- ldnsutils
- less
- locate
- lsb-release
- lsof
- man-db
- mosh
- ncdu
- ncurses-term
- psmisc
- python-is-python3
- rsync
- silversearcher-ag
- sudo
- tmux
- traceroute
- tree
- vim
# Generated, not made the default: LANG is left as it is.
utils_locales: [en_US.UTF-8, fr_FR.UTF-8]
# The LXCs were in UTC before 2026-10: their local-time timers (restic at 03:00,
# 03:15...) moved 2 hours earlier in UTC when this was applied.
utils_timezone: Europe/Paris
utils_journald_max_use: 200M
# 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:
PermitRootLogin: prohibit-password
PasswordAuthentication: "no"
KbdInteractiveAuthentication: "no"

View file

@ -1,2 +1,5 @@
--- ---
host_type: proxmox host_type: proxmox
# The host's journal holds PVE task logs too.
utils_journald_max_use: 1G

View file

@ -5,3 +5,5 @@
ansible_connection: community.proxmox.proxmox_pct_remote ansible_connection: community.proxmox.proxmox_pct_remote
ansible_host: 10.0.0.1 ansible_host: 10.0.0.1
ansible_user: root ansible_user: root
# Its own address (ansible_host above is the Proxmox host).
guest_ip: 10.0.0.250

View file

@ -15,47 +15,60 @@ all:
hosts: hosts:
proxmox: proxmox:
ansible_host: 10.0.0.1 ansible_host: 10.0.0.1
description: Proxmox VE hypervisor
lxc: lxc:
hosts: hosts:
caddy: caddy:
ansible_host: 10.0.0.10 ansible_host: 10.0.0.10
description: Caddy reverse proxy, every vhost (DNS-01)
proxmox_vmid: 100 proxmox_vmid: 100
crowdsec: crowdsec:
ansible_host: 10.0.0.11 ansible_host: 10.0.0.11
description: CrowdSec LAPI
proxmox_vmid: 101 proxmox_vmid: 101
cloud: cloud:
ansible_host: 10.0.0.12 ansible_host: 10.0.0.12
description: Nextcloud AIO (Docker)
proxmox_vmid: 102 proxmox_vmid: 102
vault: vault:
ansible_host: 10.0.0.13 ansible_host: 10.0.0.13
description: Vaultwarden (Docker)
proxmox_vmid: 103 proxmox_vmid: 103
forgejo: forgejo:
ansible_host: 10.0.0.14 ansible_host: 10.0.0.14
description: Forgejo git, SSH on 2222
proxmox_vmid: 104 proxmox_vmid: 104
restic: restic:
ansible_host: 10.0.0.15 ansible_host: 10.0.0.15
description: restic rest-server, backup target
proxmox_vmid: 105 proxmox_vmid: 105
etherpad: etherpad:
ansible_host: 10.0.0.16 ansible_host: 10.0.0.16
description: Etherpad + Postgres
proxmox_vmid: 106 proxmox_vmid: 106
jellyfin: jellyfin:
ansible_host: 10.0.0.18 ansible_host: 10.0.0.18
description: Jellyfin, media on /hdd-mirror/media
proxmox_vmid: 108 proxmox_vmid: 108
uptime-kuma: uptime-kuma:
ansible_host: 10.0.0.19 ansible_host: 10.0.0.19
description: Uptime Kuma (Docker), status.un-oeil.fr
proxmox_vmid: 109 proxmox_vmid: 109
wireguard: # no SSH login, reached through `pct exec` (host_vars/wireguard.yml) wireguard: # no SSH login, reached through `pct exec` (host_vars/wireguard.yml)
ansible_host: 10.0.0.1 ansible_host: 10.0.0.1
description: WireGuard hub, tunnel 10.10.10.0/24
proxmox_vmid: 110 proxmox_vmid: 110
leaderboard: leaderboard:
ansible_host: 10.0.0.251 ansible_host: 10.0.0.251
description: Leaderboard (Docker)
proxmox_vmid: 250 proxmox_vmid: 250
vm: vm:
hosts: hosts:
pelican-panel: pelican-panel:
ansible_host: 10.0.0.17 ansible_host: 10.0.0.17
description: Pelican Panel + local Wings
proxmox_vmid: 107 proxmox_vmid: 107
children: children:
k3s: k3s:
@ -66,27 +79,34 @@ all:
hosts: hosts:
k3s-master-1: k3s-master-1:
ansible_host: 10.0.0.131 ansible_host: 10.0.0.131
description: k3s server (cluster-init, etcd)
proxmox_vmid: 131 proxmox_vmid: 131
k3s_cluster_init: true # bootstraps etcd, the others join it k3s_cluster_init: true # bootstraps etcd, the others join it
k3s-master-2: k3s-master-2:
ansible_host: 10.0.0.132 ansible_host: 10.0.0.132
description: k3s server (etcd)
proxmox_vmid: 132 proxmox_vmid: 132
k3s-master-3: k3s-master-3:
ansible_host: 10.0.0.133 ansible_host: 10.0.0.133
description: k3s server (etcd)
proxmox_vmid: 133 proxmox_vmid: 133
k3s_workers: k3s_workers:
hosts: hosts:
k3s-worker-1: k3s-worker-1:
ansible_host: 10.0.0.141 ansible_host: 10.0.0.141
description: k3s agent + Longhorn
proxmox_vmid: 141 proxmox_vmid: 141
k3s-worker-2: k3s-worker-2:
ansible_host: 10.0.0.142 ansible_host: 10.0.0.142
description: k3s agent + Longhorn
proxmox_vmid: 142 proxmox_vmid: 142
k3s-worker-3: k3s-worker-3:
ansible_host: 10.0.0.143 ansible_host: 10.0.0.143
description: k3s agent + Longhorn
proxmox_vmid: 143 proxmox_vmid: 143
external: external:
hosts: hosts:
viarezo-vm: viarezo:
ansible_host: 10.10.10.3 # through the WireGuard tunnel ansible_host: 10.10.10.3 # through the WireGuard tunnel
description: "ViaRézo cloud VM: Wings (viarezo node), Overleaf"

View file

@ -10,21 +10,32 @@
group: root group: root
mode: "0755" mode: "0755"
# Content only: k3s restarts when this task changes, not for a mode fix. # The k3s install leaves it 0644, readable by every local user. Fixed first, so
- name: Write /etc/rancher/k3s/config.yaml # the template below only changes when the content does (and restarts k3s).
ansible.builtin.template: - name: Look for an existing config
src: k3s-config.yaml.j2 ansible.builtin.stat:
dest: /etc/rancher/k3s/config.yaml path: /etc/rancher/k3s/config.yaml
diff: false # holds the join token register: k3s_config_file
register: k3s_config
# The k3s install leaves it 0644, readable by every local user. - name: Make the existing config readable by root only
- name: Make the config readable by root only
ansible.builtin.file: ansible.builtin.file:
path: /etc/rancher/k3s/config.yaml path: /etc/rancher/k3s/config.yaml
owner: root owner: root
group: root group: root
mode: "0600" mode: "0600"
when: k3s_config_file.stat.exists
- name: Write /etc/rancher/k3s/config.yaml
ansible.builtin.template:
src: k3s-config.yaml.j2
dest: /etc/rancher/k3s/config.yaml
owner: root
group: root
# New file: created 0600. Existing one: fixed by the task above, and left
# out here so a dry run doesn't report a content change (and a restart).
mode: "{{ omit if k3s_config_file.stat.exists else '0600' }}"
diff: false # holds the join token
register: k3s_config
- name: Read the installed k3s version - name: Read the installed k3s version
ansible.builtin.command: /usr/local/bin/k3s --version ansible.builtin.command: /usr/local/bin/k3s --version

View file

@ -0,0 +1,5 @@
{{ inventory_hostname }} - {{ description | default('') }}
{{ host_type }}{{ ' ' ~ proxmox_vmid if proxmox_vmid is defined else '' }} · {{ guest_ip | default(ansible_host) }} · groups: {{ group_names | join(', ') }}
Managed by Ansible (homelab-current/ansible). Local changes may be overwritten.

View file

@ -1,25 +1,27 @@
--- ---
# Baseline for every machine, plus an opt-in system upgrade. # Baseline for every machine, plus an opt-in system upgrade.
# Settings: inventories/group_vars/all/utils.yml.
# #
# ansible-playbook playbooks/utils.yml -CD # baseline, dry run # ansible-playbook playbooks/utils.yml -CD # dry run first
# ansible-playbook playbooks/utils.yml # ansible-playbook playbooks/utils.yml
# ansible-playbook playbooks/utils.yml --tags upgrade -l lxc # apt full-upgrade # ansible-playbook playbooks/utils.yml --tags ssh,motd # only some parts
# ansible-playbook playbooks/utils.yml --tags upgrade -l lxc
# ansible-playbook playbooks/utils.yml --tags upgrade -l k3s_workers -e utils_reboot=true # ansible-playbook playbooks/utils.yml --tags upgrade -l k3s_workers -e utils_reboot=true
# #
# Baseline: apt sources on prism.viarezo.fr, a few base packages, # Tags: apt, packages, locale, time, journald, disk, ssh, hostname, motd,
# qemu-guest-agent on VMs (agent=1 is already set in Proxmox), optional timezone. # proxmox, docker, upgrade (opt-in).
# Upgrade: never runs unless --tags upgrade, refuses to run without --limit, #
# one host at a time, never on the Proxmox host (upgrade that one by hand). # 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.
# - reboot after an upgrade: VMs only. LXCs run the host's kernel.
- name: Baseline - name: Baseline
hosts: all hosts: all
gather_facts: true gather_facts: true
gather_subset: [min] gather_subset: [min]
vars: vars:
utils_packages: [curl, ca-certificates, htop, less, rsync]
# Unset = leave it alone. Changing it moves every local-time timer
# (restic at 03:00, ...) on the LXCs, which are in UTC today.
# utils_timezone: Europe/Paris
utils_mirror_rewrites: utils_mirror_rewrites:
- from: https?://deb\.debian\.org/debian(?=[/\s]|$) - from: https?://deb\.debian\.org/debian(?=[/\s]|$)
to: http://prism.viarezo.fr/debian to: http://prism.viarezo.fr/debian
@ -30,12 +32,20 @@
- from: https?://security\.ubuntu\.com/ubuntu(?=[/\s]|$) - from: https?://security\.ubuntu\.com/ubuntu(?=[/\s]|$)
to: http://prism.viarezo.fr/ubuntu to: http://prism.viarezo.fr/ubuntu
handlers:
- name: Restart journald
ansible.builtin.systemd_service:
name: systemd-journald
state: restarted
tasks: tasks:
# ---------------------------------------------------------------- apt
- name: Find apt source files - name: Find apt source files
ansible.builtin.find: ansible.builtin.find:
paths: [/etc/apt, /etc/apt/sources.list.d] paths: [/etc/apt, /etc/apt/sources.list.d]
patterns: ["sources.list", "*.list", "*.sources"] patterns: ["sources.list", "*.list", "*.sources"]
register: utils_apt_files register: utils_apt_files
tags: [apt]
- name: Point Debian/Ubuntu sources at the ViaRézo mirror - name: Point Debian/Ubuntu sources at the ViaRézo mirror
ansible.builtin.replace: ansible.builtin.replace:
@ -45,14 +55,18 @@
loop: "{{ utils_apt_files.files | product(utils_mirror_rewrites) | list }}" loop: "{{ utils_apt_files.files | product(utils_mirror_rewrites) | list }}"
loop_control: loop_control:
label: "{{ item.0.path }}: {{ item.1.to }}" label: "{{ item.0.path }}: {{ item.1.to }}"
register: utils_mirror
tags: [apt]
- name: Install base packages # ----------------------------------------------------------- packages
- name: Install admin tools
ansible.builtin.apt: ansible.builtin.apt:
name: "{{ utils_packages }}" name: "{{ utils_packages }}"
state: present state: present
install_recommends: false install_recommends: false
update_cache: true update_cache: true
cache_valid_time: 3600 cache_valid_time: "{{ 0 if utils_mirror is changed else 3600 }}"
tags: [packages]
- name: Install the QEMU guest agent (VMs only) - name: Install the QEMU guest agent (VMs only)
ansible.builtin.apt: ansible.builtin.apt:
@ -60,6 +74,7 @@
state: present state: present
install_recommends: false install_recommends: false
when: host_type == 'vm' when: host_type == 'vm'
tags: [packages]
- name: Start the QEMU guest agent (VMs only) - name: Start the QEMU guest agent (VMs only)
ansible.builtin.systemd_service: ansible.builtin.systemd_service:
@ -67,11 +82,249 @@
state: started state: started
# The unit has no [Install] section: udev starts it when the virtio port shows up. # The unit has no [Install] section: udev starts it when the virtio port shows up.
when: host_type == 'vm' and not ansible_check_mode when: host_type == 'vm' and not ansible_check_mode
tags: [packages]
# ------------------------------------------------------------- locale
- name: Install the locales package
ansible.builtin.apt:
name: locales
state: present
tags: [locale]
- name: Generate locales
community.general.locale_gen:
name: "{{ utils_locales }}"
state: present
# In a dry run, the locales package may not be installed yet.
ignore_errors: "{{ ansible_check_mode }}"
tags: [locale]
# --------------------------------------------------------------- time
- name: Set the timezone - name: Set the timezone
community.general.timezone: community.general.timezone:
name: "{{ utils_timezone }}" name: "{{ utils_timezone }}"
when: utils_timezone is defined when: utils_timezone is defined
tags: [time]
- name: List services (VMs only)
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)
ansible.builtin.apt:
name: systemd-timesyncd
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
tags: [time]
# ------------------------------------------------------- journald, disk
- name: Cap the journal size
ansible.builtin.copy:
dest: /etc/systemd/journald.conf.d/size.conf
content: |
[Journal]
SystemMaxUse={{ utils_journald_max_use }}
owner: root
group: root
mode: "0644"
notify: Restart journald
tags: [journald]
- name: Trim free space on VM disks weekly (VMs only)
ansible.builtin.systemd_service:
name: fstrim.timer
enabled: true
state: started
when: host_type in ['vm', 'external']
tags: [disk]
# ----------------------------------------------------------------- ssh
- name: Harden sshd
tags: [ssh]
block:
- name: Write the sshd drop-in
ansible.builtin.copy:
dest: /etc/ssh/sshd_config.d/10-hardening.conf
content: |
# Managed by Ansible (utils.yml). Keys only; root by key only.
{% for k, v in utils_sshd_settings.items() %}
{{ k }} {{ v }}
{% endfor %}
owner: root
group: root
mode: "0644"
register: utils_sshd_dropin
# sshd -t needs it, and it's missing while only ssh.socket is active.
- name: Create the sshd privilege separation directory
ansible.builtin.file:
path: /run/sshd
state: directory
owner: root
group: root
mode: "0755"
when: utils_sshd_dropin is changed
- name: Test the whole sshd config
ansible.builtin.command: /usr/sbin/sshd -t
changed_when: false
when: utils_sshd_dropin is changed and not ansible_check_mode
- name: Reload sshd
ansible.builtin.systemd_service:
name: ssh
state: reloaded
when: utils_sshd_dropin is changed
rescue:
- name: Remove the drop-in that broke the sshd config
ansible.builtin.file:
path: /etc/ssh/sshd_config.d/10-hardening.conf
state: absent
- name: Stop on this host
ansible.builtin.fail:
msg: "sshd -t failed with the hardening drop-in, so it was removed and sshd not reloaded."
# ------------------------------------------------------------ hostname
# The inventory name is the hostname. k3s nodes and the Proxmox host are
# only checked: renaming them renames the k8s node / breaks the PVE node.
- name: Refuse to rename a k3s node or the Proxmox host
ansible.builtin.assert:
that: ansible_facts.hostname == inventory_hostname
fail_msg: "{{ inventory_hostname }} is called {{ ansible_facts.hostname }}. Rename it by hand, not with Ansible."
quiet: true
when: host_type == 'proxmox' or inventory_hostname in groups['k3s']
tags: [hostname]
# The hostname module updates ansible_facts.hostname, so keep the old name.
- name: Remember the current hostname
ansible.builtin.set_fact:
utils_old_hostname: "{{ ansible_facts.hostname }}"
tags: [hostname]
- name: Rename the guest
when:
- utils_old_hostname != inventory_hostname
- host_type != 'proxmox' and inventory_hostname not in groups['k3s']
tags: [hostname]
block:
- name: Set the hostname in the LXC's Proxmox config
ansible.builtin.command: pct set {{ proxmox_vmid }} --hostname {{ inventory_hostname }}
delegate_to: "{{ groups['hypervisors'] | first }}"
changed_when: true
when: host_type == 'lxc'
- name: Look for cloud-init
ansible.builtin.stat:
path: /etc/cloud/cloud.cfg
register: utils_cloudinit
# cloud-init (ViaRézo VM) would put the old name back at boot.
- name: Keep cloud-init from resetting the hostname
ansible.builtin.copy:
dest: /etc/cloud/cloud.cfg.d/99-preserve-hostname.cfg
content: "preserve_hostname: true\n"
owner: root
group: root
mode: "0644"
when: utils_cloudinit.stat.exists
- name: Set the hostname now
ansible.builtin.hostname:
name: "{{ inventory_hostname }}"
- name: Rename the old hostname in /etc/hosts
ansible.builtin.replace:
path: /etc/hosts
regexp: (?<![\w.-]){{ utils_old_hostname | regex_escape }}(?![\w.-])
replace: "{{ inventory_hostname }}"
# ---------------------------------------------------------------- motd
- name: Write the motd
ansible.builtin.template:
src: motd.j2
dest: /etc/motd
owner: root
group: root
mode: "0644"
tags: [motd]
- name: Proxmox host
hosts: hypervisors
gather_facts: false
tags: [proxmox]
tasks:
# The file was fully commented out, so the host got no PVE updates at all.
- name: Enable the pve-no-subscription repository
ansible.builtin.copy:
dest: /etc/apt/sources.list.d/proxmox.sources
content: |
Types: deb
URIs: http://download.proxmox.com/debian/pve
Suites: trixie
Components: pve-no-subscription
Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg
owner: root
group: root
mode: "0644"
register: utils_pve_repo
- name: Refresh apt
ansible.builtin.apt:
update_cache: true
when: utils_pve_repo is changed
# 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)
ansible.builtin.iptables:
table: nat
chain: PREROUTING
in_interface: vmbr0
protocol: udp
match: [udp]
destination_port: "443"
jump: DNAT
to_destination: 10.0.0.250:51820
- name: Forward udp/443 to the WireGuard hub (rules.v4)
ansible.builtin.lineinfile:
path: /etc/iptables/rules.v4
line: -A PREROUTING -i vmbr0 -p udp -m udp --dport 443 -j DNAT --to-destination 10.0.0.250:51820
insertafter: ^-A PREROUTING -i vmbr0 -p udp -m udp --dport 51820 -j DNAT
- name: Docker hosts
hosts: all:!hypervisors:!k3s
gather_facts: false
tags: [docker]
tasks:
- name: Look for Docker
ansible.builtin.stat:
path: /usr/bin/docker
register: utils_docker
# Dangling images only (old layers left by updates). `prune -a` would also
# delete images no container uses right now, like Overleaf's 9 GB TeX Live
# image that only throwaway compile containers use, and break compiles.
- name: Prune dangling Docker images weekly
ansible.builtin.copy:
dest: /etc/cron.weekly/docker-prune
content: |
#!/bin/sh
# Managed by Ansible (utils.yml)
docker image prune -f >/dev/null
docker builder prune -f >/dev/null
owner: root
group: root
mode: "0755"
when: utils_docker.stat.exists
- name: Upgrade - name: Upgrade
hosts: all:!hypervisors hosts: all:!hypervisors
@ -97,7 +350,6 @@
path: /var/run/reboot-required path: /var/run/reboot-required
register: utils_reboot_required register: utils_reboot_required
# LXCs run the host's kernel: a reboot never applies a kernel update there.
- name: Reboot (VMs only, with -e utils_reboot=true) - name: Reboot (VMs only, with -e utils_reboot=true)
ansible.builtin.reboot: ansible.builtin.reboot:
reboot_timeout: 600 reboot_timeout: 600