119 lines
4.2 KiB
YAML
119 lines
4.2 KiB
YAML
---
|
|
- name: Validate current host is Debian
|
|
ansible.builtin.assert:
|
|
that:
|
|
- ansible_facts.distribution == "Debian"
|
|
fail_msg: "This role only supports Debian hosts."
|
|
|
|
- name: Validate expected source Debian major version
|
|
ansible.builtin.assert:
|
|
that:
|
|
- ansible_facts.distribution_major_version == debian_upgrade_source_major_version
|
|
fail_msg: >-
|
|
Expected Debian {{ debian_upgrade_source_major_version }} before upgrade,
|
|
found Debian {{ ansible_facts.distribution_major_version }}.
|
|
success_msg: "Host is Debian {{ debian_upgrade_source_major_version }} and ready for upgrade."
|
|
when: ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
|
|
- name: Update package cache on current release
|
|
ansible.builtin.apt:
|
|
update_cache: true
|
|
cache_valid_time: 3600
|
|
when: ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
|
|
- name: Upgrade installed packages before release change
|
|
ansible.builtin.apt:
|
|
upgrade: dist
|
|
autoremove: true
|
|
autoclean: true
|
|
when: ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
|
|
- name: Check for classic apt sources list
|
|
ansible.builtin.stat:
|
|
path: "{{ debian_upgrade_sources_list_path }}"
|
|
register: debian_upgrade_sources_list_stat
|
|
when: ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
|
|
- name: Check for deb822 apt sources
|
|
ansible.builtin.stat:
|
|
path: "{{ debian_upgrade_deb822_sources_path }}"
|
|
register: debian_upgrade_deb822_sources_stat
|
|
when: ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
|
|
- name: Back up current apt sources
|
|
ansible.builtin.copy:
|
|
src: "{{ debian_upgrade_sources_list_path }}"
|
|
dest: "{{ debian_upgrade_sources_backup_path }}"
|
|
remote_src: true
|
|
mode: "0644"
|
|
force: false
|
|
when:
|
|
- ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
- debian_upgrade_sources_list_stat.stat.exists
|
|
|
|
- name: Back up current deb822 apt sources
|
|
ansible.builtin.copy:
|
|
src: "{{ debian_upgrade_deb822_sources_path }}"
|
|
dest: "{{ debian_upgrade_deb822_sources_backup_path }}"
|
|
remote_src: true
|
|
mode: "0644"
|
|
force: false
|
|
when:
|
|
- ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
- debian_upgrade_deb822_sources_stat.stat.exists
|
|
|
|
- name: Configure Debian target release classic apt sources
|
|
ansible.builtin.template:
|
|
src: sources.list.j2
|
|
dest: "{{ debian_upgrade_sources_list_path }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
when:
|
|
- ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
- debian_upgrade_sources_list_stat.stat.exists or not debian_upgrade_deb822_sources_stat.stat.exists
|
|
|
|
- name: Configure Debian target release deb822 apt sources
|
|
ansible.builtin.template:
|
|
src: debian.sources.j2
|
|
dest: "{{ debian_upgrade_deb822_sources_path }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
when:
|
|
- ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
- debian_upgrade_deb822_sources_stat.stat.exists
|
|
|
|
- name: Update package cache for target release
|
|
ansible.builtin.apt:
|
|
update_cache: true
|
|
when: ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
|
|
- name: Perform Debian dist upgrade
|
|
ansible.builtin.apt:
|
|
upgrade: dist
|
|
autoremove: true
|
|
autoclean: true
|
|
dpkg_options: force-confdef,force-confold
|
|
environment:
|
|
DEBIAN_FRONTEND: noninteractive
|
|
APT_LISTCHANGES_FRONTEND: none
|
|
notify: reboot_after_debian_dist_upgrade
|
|
when: ansible_facts.distribution_major_version != debian_upgrade_target_major_version
|
|
|
|
- name: Flush reboot handler before verification
|
|
ansible.builtin.meta: flush_handlers
|
|
|
|
- name: Gather facts after possible upgrade
|
|
ansible.builtin.setup:
|
|
|
|
- name: Verify Debian target version
|
|
ansible.builtin.assert:
|
|
that:
|
|
- ansible_facts.distribution == "Debian"
|
|
- ansible_facts.distribution_major_version == debian_upgrade_target_major_version
|
|
fail_msg: >-
|
|
Debian upgrade did not finish as expected. Found
|
|
{{ ansible_facts.distribution }} {{ ansible_facts.distribution_major_version }}.
|
|
success_msg: "Host is running Debian {{ debian_upgrade_target_major_version }}."
|