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