tripleo-ansible/tripleo_ansible/roles/tripleo_packages/tasks/upgrade.yml

334 lines
11 KiB
YAML

---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: system_upgrade_prepare step 3
when: (step | int) == 3
tags:
- never
- system_upgrade
- system_upgrade_prepare
block:
- name: remove all OpenStack packages
shell: |-
yum -y remove *el7ost* -- \
-*openvswitch* \
-python2-babel \
-python2-dateutil \
-python2-ipaddress \
-python2-jinja2 \
-python2-markupsafe \
-python2-six
when:
- upgrade_leapp_enabled | bool
- name: install leapp
package:
name: leapp
state: latest
when:
- upgrade_leapp_enabled | bool
- name: system_upgrade_prepare step 4
when: (step | int) == 4
tags:
- never
- system_upgrade
- system_upgrade_prepare
block:
- name: run leapp upgrade (download packages)
shell: >-
{% if upgrade_leapp_devel_skip_rhsm|default(false) %}LEAPP_DEVEL_SKIP_RHSM=1{% endif %}
leapp upgrade
{% if upgrade_leapp_debug|default(true) %}--debug{% endif %}
when:
- upgrade_leapp_enabled | bool
- name: system_upgrade_run step 4
when:
- (step | int) == 4
tags:
- never
- system_upgrade
- system_upgrade_run
# In case someone needs to re-run system_upgrade_run post-tasks
# but doesn't want to reboot, they can run with
# `--skip-tags system_upgrade_reboot`.
- system_upgrade_reboot
block:
- name: reboot to perform the upgrade
reboot:
reboot_timeout: "{{ upgrade_leapp_reboot_timeout }}"
when:
- upgrade_leapp_enabled | bool
- name: Package and repo update tasks
when:
- (step | int) == 0
block:
- name: Run UpgradeInitCommand
shell: |-
set -o pipefail
if [[ -f /etc/resolv.conf.save ]]; then
rm /etc/resolv.conf.save
fi
{{ tripleo_packages_upgrade_init_command }}
args:
executable: /bin/bash
- name: Run UpgradeInitCommonCommand
shell: |-
set -o pipefail
{{ tripleo_packages_upgrade_init_common_command }}
args:
executable: /bin/bash
when:
- (tripleo_packages_upgrade_init_common_command | length) > 0
- name: Ensure TripleO prerequisite packages are installed
package:
name:
- jq
- lvm2
- net-snmp
- openstack-selinux
- os-net-config
- pacemaker
- pcs
- puppet-tripleo
- python3-heat-agent*
state: present
when:
- ansible_distribution_major_version == '8'
# With the layered product packaging, the key package is rhosp-openvswitch. It depends on
# a openvswitch package that includes the version as part of the name (e.g openvswitch2.10).
# This requires some additional special handling:
# - During an upgrade the package name for openvswitch may change so
# upgrading the currently installed package won't do anything.
# - The rhosp-openvswitch package "obsoletes" several packages,
# including older openvswitch packages. This results in a pretty
# severe uninstall/install sequence of operations that stops and
# removes openvswitch which could break network links required to
# continue the upgrade.
# - To prevent rhosp-openvswitch breaking connectivity, the currently
# installed core openvswitch packages need to be erased from the rpm
# database but leave the binaries intact. This effectively
# short-circuits the obsoletes mechanism in rhosp-openvswitch and
# leaves the core elements of openvswitch running. In the future we
# may replace this mechanism with "an upgrade on reboot". We only
# do this for the core openvswitch packages so other packages
# obsoleted by rhosp-openvswitch will be removed when
# rhosp-openvswitch is installed/upgraded.
# - Neither the rhosp-openvswitch nor openvswitch{m.n} package enables
# or starts the systemd service so there must always be a task
# to ensure that it is enabled or OpenvSwitch functionality won't be
# available on reboot.
# - With LP, we expect that the core openvswitch package name will
# change with every major upgrade so this special handling will
# eventually replace the special handling of upgrading the
# openvswitch package "in place"
- name: Block for gathering information for upgrading OpenvSwitch layered product packaging
when: (step | int) == 2
block:
- name: Process rhosp-openvswitch layered package for new version number
shell: |-
set -o pipefail
yum info -q rhosp-openvswitch | awk '/^Version/{print $NF}'
register: rhosp_package_result
failed_when: false
- name: Set fact for triggering OpenvSwitch layered product package handling
set_fact:
ovs_lp_packaging: "{{ rhosp_package_result.rc == 0 }}"
- name: Capture the expected OpenvSwitch version.
set_fact:
new_ovs_version: "{{ rhosp_package_result.stdout }}"
when:
- ovs_lp_packaging | default(false)
- name: Get current OpenvSwitch package name
register: ovs_pkg_out
shell: |-
set -o pipefail
rpm -qa | awk -F- '/^(openvswitch[0-9]+\.[0-9]+-|openvswitch-2)/{print $1}'
- name: Get version from current OpenvSwitch package
register: ovs_version_out
shell: |-
set -o pipefail
rpm -qi "{{ ovs_pkg_out.stdout }}" | awk '/^Version/{print $NF}'
- name: split numeric version for OpenvSwitch into parts
set_fact:
ovs_version_parts: "{{ ovs_version_out.stdout.split('.') }}"
- name: get major minor version for OpenvSwitch package naming
set_fact:
current_ovs_version: "{{ ovs_version_parts[0] }}.{{ ovs_version_parts[1] }}"
- name: get OpenvSwitch major version
set_fact:
current_ovs_major_version: "{{ ovs_version_parts[0]|int }}"
- name: get OpenvSwitch minor version
set_fact:
current_ovs_minor_version: "{{ ovs_version_parts[1]|int }}"
- name: Block for upgrading OpenvSwitch when layer package is present
when:
- (step | int) == 2
- ovs_lp_packaging | default(false)
block:
- name: set current OpenvSwitch package suffix if old version is layered product format
set_fact:
package_suffix: "{{ current_ovs_version }}"
when:
- ((current_ovs_major_version | int) >= 3) or
((current_ovs_minor_version | int) >= 10)
- name: remove old OpenvSwitch package(s) if version doesn't match
shell: |-
rpm -e --noscripts \
--nopreun \
--nopostun \
--notriggers \
--nodeps $(rpm -qa 'openvswitch{{ package_suffix|default('') }}*' | grep -v 'selinux')
args:
warn: false
when:
- new_ovs_version != current_ovs_version
- name: install/upgrade OpenvSwitch LP package
package:
name: rhosp-openvswitch
state: latest
notify: start openvswitch
- name: set flag to skip other upgrade steps since OpenvSwitch is already upgraded!
set_fact:
run_ovs_update: false
- name: Check for openvswitch upgrade if not layered package installs
when:
- (step | int) == 2
- run_ovs_update|default(true)
block:
- name: check if an upgrade is required
register: ovs_need_upgrade
failed_when: false
shell: |
yum check-upgrade openvswitch | awk '/openvswitch/{print}'
- name: Check openvswitch packaging.
shell: |-
set -o pipefail
rpm -q --scripts openvswitch | awk '/postuninstall/,/*/' | grep -q "systemctl.*try-restart"
register: ovs_packaging_issue
failed_when: false
- name: Upgrade openvswitch
when:
- (step | int) == 2
- run_ovs_update | default(true)
- ovs_packaging_issue.rc == 0
- ovs_need_upgrade.stdout | default('')
block:
- name: "Ensure empty directory: emptying."
file:
state: absent
path: /root/OVS_UPGRADE
- name: "Ensure empty directory: creating."
file:
state: directory
path: /root/OVS_UPGRADE
owner: root
group: root
mode: 0750
- name: Make yum cache.
command: yum makecache
- name: Download OVS packages
shell: |-
if command -v yumdownloader; then
yumdownloader --destdir /root/OVS_UPGRADE --resolve openvswitch
else
dnf download --destdir /root/OVS_UPGRADE --resolve openvswitch
fi
- name: Get rpm list for manual upgrade of OVS.
shell: ls -1 /root/OVS_UPGRADE/*.rpm
register: ovs_list_of_rpms
- name: Manual upgrade of OVS
shell: |
rpm -U --replacepkgs --notriggerun --nopostun {{ item }}
args:
chdir: /root/OVS_UPGRADE
loop: "{{ ovs_list_of_rpms.stdout_lines }}"
notify: "start openvswitch"
- name: Install libibverbs (https://bugs.launchpad.net/tripleo/+bug/1817743)
when:
- (step | int) == 2
package:
name: libibverbs
state: installed
- name: Check for os-net-config upgrade
shell: |-
set -o pipefail
yum check-upgrade | awk '/os-net-config/{print}'
failed_when: false
register: os_net_config_need_upgrade
when:
- (step | int) == 3
- name: Check that os-net-config has configuration
shell: test -s /etc/os-net-config/config.json
register: os_net_config_has_config
failed_when: false
when:
- (step | int) == 3
- name: os-net-config block
when:
- (step | int) == 3
- os_net_config_need_upgrade.rc == 0
- (os_net_config_need_upgrade.stdout | length) > 0
- os_net_config_has_config.rc == 0
block:
- name: Upgrade os-net-config
package:
name: os-net-config
state: latest
- name: take new os-net-config parameters into account now
command: os-net-config --no-activate -c /etc/os-net-config/config.json -v --detailed-exit-codes
register: os_net_config_upgrade
failed_when: os_net_config_upgrade.rc not in [0,2]
changed_when: os_net_config_upgrade.rc == 2
# Ansbile cannot upgrade itself as it will cause the current execution to fail.
# https://github.com/ansible/ansible/issues/56636
- name: Update all packages
when: (step | int) == 3
yum:
name: '*'
state: latest
exclude: ansible