Files
Ansible-roles/unattended_upgrades/tasks/main.yml
T

64 lines
2.3 KiB
YAML

---
- name: Require an allowed origin for the distribution
ansible.builtin.assert:
that:
- (unattended_upgrades.origins_pattern[ansible_distribution] | default([]) + unattended_upgrades.allowed_origins[ansible_distribution] | default([])) | length > 0
fail_msg: unattended_upgrades has no origins for {{ ansible_distribution }}
- name: Install unattended-upgrades
ansible.builtin.apt:
name: unattended-upgrades
state: present
- name: Enable the daily package list update and upgrade
ansible.builtin.template:
src: 20auto-upgrades.j2
dest: /etc/apt/apt.conf.d/20auto-upgrades
mode: "0644"
# Separate file, the package owns 50unattended-upgrades.
- name: Configure unattended-upgrades
ansible.builtin.template:
src: 52unattended-upgrades-local.j2
dest: /etc/apt/apt.conf.d/52unattended-upgrades-local
mode: "0644"
# needrestart (Ubuntu default) restarts every service that uses an upgraded library, containerd and netbird included:
# after a libc upgrade the dead FUSE mounts hung systemd-resolved on antius and the node went NotReady (2026-11-14).
# List only; the services pick up the library at the next reboot, which HostRebootRequired tracks.
- name: Check for needrestart
ansible.builtin.stat:
path: /etc/needrestart/conf.d
register: unattended_upgrades_needrestart
- name: Let needrestart list the services instead of restarting them
ansible.builtin.template:
src: needrestart-list-only.conf.j2
dest: /etc/needrestart/conf.d/90-list-only.conf
mode: "0644"
when: unattended_upgrades_needrestart.stat.exists
# Debian installs apt-listchanges with email_address=root, which mails the NEWS of every
# unattended upgrade through the mail relay.
- name: Check for the apt-listchanges config
ansible.builtin.stat:
path: /etc/apt/listchanges.conf
register: unattended_upgrades_listchanges
- name: Disable the apt-listchanges mails
ansible.builtin.lineinfile:
path: /etc/apt/listchanges.conf
regexp: '^email_address='
line: email_address=none
insertafter: '^\[apt\]'
when: unattended_upgrades_listchanges.stat.exists
- name: Enable the apt timers
ansible.builtin.systemd:
name: "{{ item }}"
enabled: true
state: started
loop:
- apt-daily.timer
- apt-daily-upgrade.timer