Add in place os upgrade for Debian and Ubuntu
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,45 @@
|
||||
---
|
||||
# tasks file for ensure_os_upgrade - Fedora
|
||||
- name: Ensure System-upgrade Download
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Fedora'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.package_list is defined
|
||||
- ensure_os_upgrade.package_list is iterable
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
- ansible_facts["distribution_major_version"]|int < ensure_os_upgrade.target_version|int
|
||||
ansible.builtin.shell: >
|
||||
dnf -y system-upgrade download --refresh --releasever={{ ensure_os_upgrade.target_version|int }}
|
||||
- name: Ensure System-upgrade Reboot
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Fedora'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.package_list is defined
|
||||
- ensure_os_upgrade.package_list is iterable
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
- ansible_facts["distribution_major_version"]|int < ensure_os_upgrade.target_version|int
|
||||
async: 1
|
||||
poll: 0
|
||||
ansible.builtin.shell: >
|
||||
sleep 5 && dnf -y system-upgrade reboot
|
||||
- name: Wait For The Reboot
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Fedora'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.package_list is defined
|
||||
- ensure_os_upgrade.package_list is iterable
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
- ansible_facts["distribution_major_version"]|int < ensure_os_upgrade.target_version|int
|
||||
ansible.builtin.wait_for:
|
||||
connect_timeout: '5'
|
||||
delay: '300'
|
||||
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
|
||||
port: '22'
|
||||
search_regex: OpenSSH
|
||||
sleep: '15'
|
||||
timeout: '1800'
|
||||
vars:
|
||||
ansible_connection: local
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
# tasks file for ensure_os_upgrade - Ubuntu
|
||||
- name: Ensure update-manager-core is installed
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Ubuntu'
|
||||
- ensure_os_upgrade is defined
|
||||
ansible.builtin.apt:
|
||||
name: update-manager-core
|
||||
state: present
|
||||
|
||||
- name: Configure Ubuntu Release Upgrade Prompt
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Ubuntu'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/update-manager/release-upgrades
|
||||
regexp: '^Prompt='
|
||||
line: "Prompt={{ 'lts' if ensure_os_upgrade.target_version.endswith('.04') else 'normal' }}"
|
||||
|
||||
- name: Execute Ubuntu Release Upgrade
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Ubuntu'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
- ansible_facts["distribution_version"] != ensure_os_upgrade.target_version
|
||||
ansible.builtin.command: do-release-upgrade -f DistUpgradeViewNonInteractive
|
||||
environment:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
DPKG_OPTIONS: '-o Dpkg::Options::="--force-confnew" -o Dpkg::Options::="--force-confdef"'
|
||||
|
||||
- name: Reboot Ubuntu After Upgrade
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Ubuntu'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
- ansible_facts["distribution_version"] != ensure_os_upgrade.target_version
|
||||
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
|
||||
@@ -62,49 +62,25 @@
|
||||
notify:
|
||||
- Ensure_Os_Upgrade.Package_Facts
|
||||
- Ensure_Os_Upgrade.Service_Facts
|
||||
- name: Ensure System-upgrade Download
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Fedora'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.package_list is defined
|
||||
- ensure_os_upgrade.package_list is iterable
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
- ansible_facts["distribution_major_version"]|int < ensure_os_upgrade.target_version|int
|
||||
ansible.builtin.shell: >
|
||||
dnf -y system-upgrade download --refresh --releasever={{ ensure_os_upgrade.target_version|int }}
|
||||
- name: Ensure System-upgrade Reboot
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Fedora'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.package_list is defined
|
||||
- ensure_os_upgrade.package_list is iterable
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
- ansible_facts["distribution_major_version"]|int < ensure_os_upgrade.target_version|int
|
||||
async: 1
|
||||
poll: 0
|
||||
ansible.builtin.shell: >
|
||||
sleep 5 && dnf -y system-upgrade reboot
|
||||
- name: Wait For The Reboot
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["distribution"] == 'Fedora'
|
||||
- ensure_os_upgrade is defined
|
||||
- ensure_os_upgrade.package_list is defined
|
||||
- ensure_os_upgrade.package_list is iterable
|
||||
- ensure_os_upgrade.target_version is defined
|
||||
- ansible_facts["distribution_major_version"]|int < ensure_os_upgrade.target_version|int
|
||||
ansible.builtin.wait_for:
|
||||
connect_timeout: '5'
|
||||
delay: '300'
|
||||
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
|
||||
port: '22'
|
||||
search_regex: OpenSSH
|
||||
sleep: '15'
|
||||
timeout: '1800'
|
||||
- name: Include Vendor / Version Specific Tasks
|
||||
when: ["ansible_facts[\"system\"] == 'Linux'"]
|
||||
ansible.builtin.include_tasks:
|
||||
file: '{{ lookup("first_found", findme) }}'
|
||||
vars:
|
||||
ansible_connection: local
|
||||
findme:
|
||||
files:
|
||||
- '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"]
|
||||
}}-{{ ansible_facts["architecture"] }}.yml'
|
||||
- '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"]
|
||||
}}-default.yml'
|
||||
- '{{ ansible_facts["distribution"] }}-default.yml'
|
||||
- '{{ ansible_facts["os_family"] }}-{{ ansible_facts["distribution_major_version"]
|
||||
}}-{{ ansible_facts["architecture"] }}.yml'
|
||||
- '{{ ansible_facts["os_family"] }}-{{ ansible_facts["distribution_major_version"]
|
||||
}}-default.yml'
|
||||
- '{{ ansible_facts["os_family"] }}-default.yml'
|
||||
- default.yml
|
||||
errors: ignore
|
||||
- name: Gather Facts
|
||||
ansible.builtin.setup:
|
||||
notify:
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
# vars file for ensure_os_upgrade - Debian 11 (Bullseye)
|
||||
# Goal: Upgrade to oldest in-support version (Debian 12 Bookworm)
|
||||
target_codename: 'bookworm'
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
# vars file for ensure_os_upgrade - Debian 12 (Bookworm)
|
||||
# Currently in-support. No automatic upgrade to Debian 13 (Trixie).
|
||||
# target_codename: 'trixie'
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
# vars file for ensure_os_upgrade - Ubuntu 20.04 (Focal Fossa)
|
||||
# Goal: Upgrade to oldest in-support version (Ubuntu 22.04 LTS)
|
||||
target_version: '22.04'
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
# vars file for ensure_os_upgrade - Ubuntu 22.04 (Jammy Jellyfish)
|
||||
# Currently in-support LTS. No automatic upgrade to 24.04.
|
||||
# target_version: '24.04'
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
# vars file for ensure_os_upgrade - Ubuntu 24.04 (Noble Numbat)
|
||||
# Currently in-support LTS. No automatic upgrade to 26.04.
|
||||
# target_version: '26.04'
|
||||
Reference in New Issue
Block a user