Update almalinux-deploy.sh for --preserve-rhsm - #278
Conversation
| DOWNGRADE='NO' | ||
| REPO_URL=https://repo.almalinux.org/almalinux | ||
| LOCAL_REPO='NO' | ||
| PRESERVE_RHSM='NO' |
There was a problem hiding this comment.
To fix the line 1630: DNF_UPGRADE: unbound variable
| PRESERVE_RHSM='NO' | |
| PRESERVE_RHSM='NO' | |
| DNF_UPGRADE='NO' |
| for pkg in $(rpm -qa | grep -E 'shim|fwupd|grub2'); do | ||
| if [[ "AlmaLinux" != "$(rpm -q --queryformat '%{vendor}' "$pkg")" ]]; then | ||
| yum reinstall "${pkg}" -y | ||
| # There is a timing issue where some packages are available on RHEL but not yet on AlmaLinux mirrors, so we ignore errors here |
There was a problem hiding this comment.
Secure Boot package reinstall is a safety regression and unrelated to the feature. And we can't ignore errors here.
| # There is a timing issue where some packages are available on RHEL but not yet on AlmaLinux mirrors, so we ignore errors here |
| if [[ "AlmaLinux" != "$(rpm -q --queryformat '%{vendor}' "$pkg")" ]]; then | ||
| yum reinstall "${pkg}" -y | ||
| # There is a timing issue where some packages are available on RHEL but not yet on AlmaLinux mirrors, so we ignore errors here | ||
| yum reinstall -y "${pkg}" || true |
There was a problem hiding this comment.
If the AlmaLinux-signed shim/kernel isn't actually installed, a Secure Boot machine won't boot after migration.
| yum reinstall -y "${pkg}" || true | |
| yum reinstall "${pkg}" -y |
| kernel_package="$(rpm -qf "$kernel_path")" | ||
| if [[ "AlmaLinux" != "$(rpm -q --queryformat '%{vendor}' "${kernel_package}")" ]]; then | ||
| yum reinstall "${kernel_package}" -y | ||
| # There is a timing issue where kernel packages are available on RHEL but not yet on AlmaLinux mirrors, so we ignore errors here |
There was a problem hiding this comment.
Secure Boot package reinstall is a safety regression and unrelated to the feature. And we can't ignore errors here.
| # There is a timing issue where kernel packages are available on RHEL but not yet on AlmaLinux mirrors, so we ignore errors here |
| if [[ "AlmaLinux" != "$(rpm -q --queryformat '%{vendor}' "${kernel_package}")" ]]; then | ||
| yum reinstall "${kernel_package}" -y | ||
| # There is a timing issue where kernel packages are available on RHEL but not yet on AlmaLinux mirrors, so we ignore errors here | ||
| yum reinstall -y "$kernel_package" || true |
There was a problem hiding this comment.
If the AlmaLinux-signed shim/kernel isn't actually installed, a Secure Boot machine won't boot after migration.
| yum reinstall -y "$kernel_package" || true | |
| yum reinstall "${pkg}" -y |
| LOCAL_REPO='NO' | ||
| REPO_URL='' | ||
| DNF_UPGRADE='NO' | ||
| dnf install -y python3-dnf-plugin-post-transaction-actions >/dev/null |
There was a problem hiding this comment.
System-modifying in the option-parsing block, before root check, logging, etc ...
| dnf install -y python3-dnf-plugin-post-transaction-actions >/dev/null |
| REPO_URL='' | ||
| DNF_UPGRADE='NO' | ||
| dnf install -y python3-dnf-plugin-post-transaction-actions >/dev/null | ||
| echo -e '# AlmaLinux Repo files break dnf if no proxy is available\nalmalinux-re*:in:/usr/bin/rm -f /etc/yum.repos.d/almalinux*.repo' > /etc/dnf/plugins/post-transaction-actions.d/almalinux-repos.conf |
There was a problem hiding this comment.
Move this into a proper stage function called from main() (after assert_run_as_root)
| echo -e '# AlmaLinux Repo files break dnf if no proxy is available\nalmalinux-re*:in:/usr/bin/rm -f /etc/yum.repos.d/almalinux*.repo' > /etc/dnf/plugins/post-transaction-actions.d/almalinux-repos.conf |
| local release_path | ||
| local panel_type | ||
| local panel_version | ||
| assert_run_as_root |
There was a problem hiding this comment.
Install the dnf post-transaction-actions plugin and a hook (new function)
| setup_preserve_rhsm_hook |
| report_step_done "Remove RHEL repositories' files if any" | ||
| save_status_of_stage "remove_redhat_repo_files" | ||
| } | ||
|
|
There was a problem hiding this comment.
| # Installs the dnf post-transaction-actions plugin and a hook which removes | |
| # AlmaLinux repository files as soon as almalinux-release/almalinux-repos | |
| # create them. Only used with --preserve-rhsm, where repositories are | |
| # managed by subscription-manager (Foreman/Katello). | |
| setup_preserve_rhsm_hook() { | |
| if [[ "${PRESERVE_RHSM}" != "YES" ]]; then | |
| return 0 | |
| fi | |
| if get_status_of_stage "setup_preserve_rhsm_hook"; then | |
| return 0 | |
| fi | |
| local -r step='Install dnf post-transaction-actions hook for --preserve-rhsm' | |
| local -r hook_dir='/etc/dnf/plugins/post-transaction-actions.d' | |
| local output | |
| if ! output=$(dnf install -y python3-dnf-plugin-post-transaction-actions 2>&1); then | |
| report_step_error "${step}" "${output}" | |
| exit 1 | |
| fi | |
| mkdir -p "${hook_dir}" | |
| printf '%s\n' '# AlmaLinux Repo files break dnf if no proxy is available' \ | |
| 'almalinux-re*:in:/usr/bin/rm -f /etc/yum.repos.d/almalinux*.repo' \ | |
| > "${hook_dir}/almalinux-repos.conf" | |
| report_step_done "${step}" | |
| save_status_of_stage "setup_preserve_rhsm_hook" | |
| } | |
Adds
--preserve-rhsmto stop the script from destroying repositories on enterprise servers managed by Foreman (or RedHat Satellite for the mega rich).Also removes the need for servers to have access to the internet for updates.
Testing
Tested on RHEL v8, 9 and 10 using Foreman 3.19 with Katello 4.21
Also used in production on several servers so far.
Added
README_PRESERVE_RHSM.mdto further explain the expected setup for using this option.Addresses #276
Peter