Add in place os upgrade for Debian and Ubuntu

This commit is contained in:
2026-08-11 00:08:41 -05:00
parent 0e18e3bdbb
commit 8240771758
9 changed files with 185 additions and 42 deletions
@@ -0,0 +1,54 @@
---
# tasks file for ensure_os_upgrade - Debian
- name: Update sources.list for Debian Upgrade
when:
- ansible_facts["system"] == 'Linux'
- ansible_facts["os_family"] == 'Debian'
- ensure_os_upgrade is defined
- ensure_os_upgrade.target_codename is defined
ansible.builtin.replace:
path: /etc/apt/sources.list
regexp: '^(deb(?:-src)?\s+https?://[a-zA-Z0-9.-]*debian\.org\S*\s+)\b{{ ansible_facts["lsb"]["codename"] }}\b(.*)$'
replace: '\1{{ ensure_os_upgrade.target_codename }}\2'
backup: yes
- name: Safe Upgrade Debian Packages
when:
- ansible_facts["system"] == 'Linux'
- ansible_facts["os_family"] == 'Debian'
- ensure_os_upgrade is defined
- ensure_os_upgrade.target_codename is defined
ansible.builtin.apt:
update_cache: yes
upgrade: safe
dpkg_options: 'force-confnew,force-confdef'
environment:
DEBIAN_FRONTEND: noninteractive
- name: Full Upgrade Debian Packages
when:
- ansible_facts["system"] == 'Linux'
- ansible_facts["os_family"] == 'Debian'
- ensure_os_upgrade is defined
- ensure_os_upgrade.target_codename is defined
ansible.builtin.apt:
upgrade: dist
dpkg_options: 'force-confnew,force-confdef'
autoremove: yes
autoclean: yes
environment:
DEBIAN_FRONTEND: noninteractive
- name: Reboot Debian After Upgrade
when:
- ansible_facts["system"] == 'Linux'
- ansible_facts["os_family"] == 'Debian'
- ensure_os_upgrade is defined
- ensure_os_upgrade.target_codename is defined
ansible.builtin.reboot:
msg: "Rebooting for OS Upgrade"
connect_timeout: 5
reboot_timeout: 1800
pre_reboot_delay: 5
post_reboot_delay: 15
test_command: whoami