jjb/ansible: Drop support for Ubuntu bionic
[lttng-ci.git] / automation / ansible / playbooks / release-upgrade.yml
CommitLineData
6b6cc731
KS
1---
2- name: Set next release
3 hosts: all
4 tasks:
6b6cc731
KS
5 - set_fact:
6 release_index: "{{lookup('ansible.utils.index_of', data=lookup('vars', ansible_distribution+'_releases', default=[]), test='eq', value=ansible_distribution_release)}}"
7 # If there is not a next release available (as defined below in Debian_releasess
8 # or Ubuntu_releases), the execution of the playbook will fail at this step.
9 - set_fact:
10 next_release: "{{lookup('vars', ansible_distribution+'_releases')[release_index|int + 1]}}"
11 - debug:
491b5c0e 12 msg: "Upgrading from {{ansible_distribution_release}} to {{next_release}}"
6b6cc731
KS
13 vars:
14 # 'stable' releases ordered from oldest to newest
15 Debian_releases:
16 - buster
17 - bullseye
18 - bookworm
19 Ubuntu_releases:
6b6cc731
KS
20 - focal
21 - jammy
22- name: Run any outstanding upgrades
23 hosts: all
24 tasks:
25 - apt:
26 update_cache: true
27 - apt:
28 upgrade: dist
29 - apt:
30 autoremove: true
31 purge: true
32- name: Pre-upgrade backups
33 hosts: all
34 tasks:
35 - name: Check if /etc is a git repo
36 register: etckeeper
37 command:
38 cmd: test -d /etc/.git
39 ignore_errors: true
40 - name: Tag etc configuration
41 when: etckeeper.rc == 0
42 block:
43 - command:
44 chdir: /etc
45 argv:
46 - git
47 - tag
48 - "pre-{{next_release}}"
49 - command:
50 chdir: /etc
51 cmd: 'git gc --prune'
52 - name: Backup package state
53 block:
54 - shell:
55 cmd: "tar czf /var/backups/pre-{{next_release}}-backup.tgz /etc /var/lib/dpkg /var/lib/apt/extended_states"
56 # Mitogen doesn't seem to work with the 'archive' module, since tarfile is
57 # "present in the Mitogent importer blacklist", so a shell command is used
58 # here instead
59 warn: false
60 - shell:
61 cmd: "dpkg --get-selections '*' > /var/backups/dpkg-selections-pre-{{next_release}}.txt"
62 - file:
63 path: "{{item}}"
64 mode: '0600'
65 with_items:
66 - "/var/backups/pre-{{next_release}}-backup.tgz"
67 - "/var/backups/dpkg-selections-pre-{{next_release}}.txt"
770f5ebe
KS
68- name: Update hostname
69 hosts: all
70 vars:
71 # eg. ansible-playbook -e '{"UPDATE_HOSTNAME":true}' playbooks/release-upgrade.yml
72 update_hostname: "{{lookup('vars', 'UPDATE_HOSTNAME', default='false')}}"
73 tasks:
74 - debug:
75 msg: "update_hostname: {{update_hostname}}"
76 - replace:
77 path: /etc/hostname
78 regexp: "{{ansible_distribution_release}}"
79 replace: "{{next_release}}"
80 when: update_hostname | bool
81 - replace:
82 path: /etc/hostname
83 regexp: "deb{{ansible_distribution_version}}"
84 replace: "deb{{ansible_distribution_version|int + 1 }}"
85 when: update_hostname | bool and ansible_distribution == 'Debian'
6b6cc731
KS
86- name: Debian major version upgrade
87 hosts: all
6b6cc731
KS
88 vars:
89 apt_noninteractive_environment:
90 DEBIAN_FRONTEND: noninteractive
91 APT_LISTCHANGES_FRONTEND: mail
7033367a 92 apt_common_options: "-o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confnew'"
6b6cc731 93 tasks:
7a1ce7d7
KS
94 - import_tasks: ../tasks/debian_release_upgrade.yml
95 when: ansible_distribution == 'Debian'
6b6cc731
KS
96- name: Ubuntu major version upgrade
97 hosts: all
6b6cc731
KS
98 tasks:
99 - name: Do release upgrade
7a1ce7d7 100 when: ansible_distribution == 'Ubuntu'
6b6cc731
KS
101 command:
102 cmd: 'do-release-upgrade -m server --frontend=DistUpgradeViewNonInteractive'
103- name: Post-upgrade tasks
104 hosts: all
105 tasks:
106 - name: Mark rsyslog as auto
107 when: next_release == 'bookworm'
108 command:
109 cmd: 'apt-mark auto rsyslog'
110 - name: Autoremove any packages
111 apt:
112 autoremove: true
113 purge: true
114 - name: Clean apt cache
115 apt:
116 autoclean: true
This page took 0.02646 seconds and 4 git commands to generate.