From 78f8520bc3f84c9e81af9b99755791ffd5f27309 Mon Sep 17 00:00:00 2001 From: Scott Vick <70352612+scott-vick@users.noreply.github.com> Date: Tue, 29 Aug 2023 10:37:38 -0500 Subject: [PATCH] Fix for Pathing issue with analysis (#117) * Fix for Pathing issue with analysis - Added default variable "os_path" - Added extra parameter to the leapp analysis shell command to override or add to the default $PATH on the target node * Fix for Pathing issues for shell commands - Added extra parameter to the shell commands to override or add to the default $PATH on the target node --- roles/analysis/README.md | 1 + roles/analysis/defaults/main.yml | 1 + roles/analysis/handlers/main.yml | 1 + roles/analysis/tasks/analysis-leapp.yml | 1 + roles/analysis/tasks/analysis-preupg.yml | 3 +++ roles/analysis/tasks/main.yml | 1 + roles/common/handlers/main.yml | 1 + roles/upgrade/README.md | 1 + roles/upgrade/tasks/check-for-old-packages.yml | 1 + roles/upgrade/tasks/grub2-upgrade.yml | 5 ++++- roles/upgrade/tasks/leapp-post-upgrade-selinux.yml | 1 + roles/upgrade/tasks/leapp-post-upgrade.yml | 11 +++++++++-- roles/upgrade/tasks/leapp-upgrade.yml | 5 ++++- .../tasks/redhat-upgrade-tool-post-upgrade.yml | 1 + roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml | 6 +++++- 15 files changed, 35 insertions(+), 5 deletions(-) diff --git a/roles/analysis/README.md b/roles/analysis/README.md index 0d5d645..700b175 100644 --- a/roles/analysis/README.md +++ b/roles/analysis/README.md @@ -30,6 +30,7 @@ Activation keys provide a method to identify content views available from Red Ha | leapp_answerfile | Multi-line String | | If defined, this s written to `/var/log/leapp/answerfile` before generating the pre-upgrade report. | | leapp_preupg_opts | String | | Optional string to define command line options to be passed to the `leapp` command when running the pre-upgrade. | | post_reboot_delay | Int | 120 | Optional integer to pass to the reboot post_reboot_delay option. | +| os_path | String | Option string to override the $PATH variable used on the target node | ## Example playbook diff --git a/roles/analysis/defaults/main.yml b/roles/analysis/defaults/main.yml index 2ca8308..bb4097b 100644 --- a/roles/analysis/defaults/main.yml +++ b/roles/analysis/defaults/main.yml @@ -55,4 +55,5 @@ leapp_repos_enabled: [] post_reboot_delay: 120 +os_path: $PATH ... diff --git a/roles/analysis/handlers/main.yml b/roles/analysis/handlers/main.yml index 3904b20..712dc88 100644 --- a/roles/analysis/handlers/main.yml +++ b/roles/analysis/handlers/main.yml @@ -10,6 +10,7 @@ # TODO: Having issues with community.general.redhat_subscription and subscription-manager on RHEL 6. - name: Register to pre leapp activation key RHEL 6 ansible.builtin.shell: > + export PATH={{ os_release }}; subscription-manager register --org="{{ satellite_organization }}" --activationkey="{{ satellite_activation_key_pre_leapp }}" diff --git a/roles/analysis/tasks/analysis-leapp.yml b/roles/analysis/tasks/analysis-leapp.yml index a420fa5..0313d12 100644 --- a/roles/analysis/tasks/analysis-leapp.yml +++ b/roles/analysis/tasks/analysis-leapp.yml @@ -43,6 +43,7 @@ - name: Leapp preupgrade report ansible.builtin.shell: > + export PATH={{ os_path }} set -o pipefail; leapp preupgrade {{ leapp_preupg_opts }} diff --git a/roles/analysis/tasks/analysis-preupg.yml b/roles/analysis/tasks/analysis-preupg.yml index 1ef642a..55277ed 100644 --- a/roles/analysis/tasks/analysis-preupg.yml +++ b/roles/analysis/tasks/analysis-preupg.yml @@ -2,6 +2,7 @@ # TODO: Having issues with community.general.redhat_subscription and subscription-manager on RHEL 6. - name: Register to upgrade activation key ansible.builtin.shell: > + export PATH={{ os_release }}; subscription-manager register --org="{{ satellite_organization }}" --activationkey="{{ satellite_activation_key_pre_leapp }}" @@ -16,6 +17,7 @@ - name: Enable requisite RHUI repos ansible.builtin.shell: | + export PATH={{ os_release }} set -o pipefail yum-config-manager --enable {{ item }} loop: "{{ analysis_repos_el6 }}" @@ -48,6 +50,7 @@ - name: Run preupg ansible.builtin.shell: > + export PATH={{ os_release }}; set -o pipefail; preupg --force --text 2>&1 | tee -a {{ log_file }} diff --git a/roles/analysis/tasks/main.yml b/roles/analysis/tasks/main.yml index fb2c5c1..509e2c1 100644 --- a/roles/analysis/tasks/main.yml +++ b/roles/analysis/tasks/main.yml @@ -25,6 +25,7 @@ - name: Capture a list of non-rhel versioned packages ansible.builtin.shell: cmd: >- + export PATH={{ os_release }}; set -o pipefail; rpm -qa | grep -ve '[\.|+]el{{ ansible_distribution_major_version }}' | grep -vE '^(gpg-pubkey|libmodulemd|katello-ca-consumer)' | diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml index 5e53a72..a669426 100644 --- a/roles/common/handlers/main.yml +++ b/roles/common/handlers/main.yml @@ -22,6 +22,7 @@ - name: Rename log file ansible.builtin.shell: | + export PATH={{ os_release }} mv {{ log_file }} {{ log_file }}-{{ ansible_date_time.iso8601_basic_short }} listen: Archive log file ... diff --git a/roles/upgrade/README.md b/roles/upgrade/README.md index 7edb7bc..6003dd7 100644 --- a/roles/upgrade/README.md +++ b/roles/upgrade/README.md @@ -16,6 +16,7 @@ Additionally a list of any non-Red Hat RPM packages that were installed on the s | crypto_policy | "DEFAULT" | System-wide cryptographic to set, e.g., "FUTURE", "DEFAULT:SHA1", etc. Refer to the crypto-policies (7) man page for more information. | | post_reboot_delay | 120 | Optional integer to pass to the reboot post_reboot_delay option. | | update_grub_to_grub_2 | false | Boolean to control whether grub gets upgraded to grub 2 in post RHEL 6 to 7 upgrade. | +| os_path | $PATH | Variable used to override the default $PATH environmental variable on the target node ## Example playbook diff --git a/roles/upgrade/tasks/check-for-old-packages.yml b/roles/upgrade/tasks/check-for-old-packages.yml index eff1d86..239cdcb 100644 --- a/roles/upgrade/tasks/check-for-old-packages.yml +++ b/roles/upgrade/tasks/check-for-old-packages.yml @@ -3,6 +3,7 @@ - name: Search for old packages and packages not versioned by rhel release ansible.builtin.shell: cmd: >- + export PATH={{ os_release }}; set -o pipefail; rpm -qa | grep -ve '[\.|+]el{{ ansible_distribution_major_version }}' | diff --git a/roles/upgrade/tasks/grub2-upgrade.yml b/roles/upgrade/tasks/grub2-upgrade.yml index 06876d4..87e8723 100644 --- a/roles/upgrade/tasks/grub2-upgrade.yml +++ b/roles/upgrade/tasks/grub2-upgrade.yml @@ -40,10 +40,13 @@ grub_boot_device: "{{ boot_device_dict.device | regex_replace('[1-9]$', '') }}" - name: Run grub2-install - ansible.builtin.shell: grub2-install {{ grub_boot_device }} + ansible.builtin.shell: | + export PATH={{ os_release }} + grub2-install {{ grub_boot_device }} - name: Run grub2-mkconfig ansible.builtin.shell: | + export PATH={{ os_release }} set -o pipefail grub2-mkconfig -o /boot/grub2/grub.cfg grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg diff --git a/roles/upgrade/tasks/leapp-post-upgrade-selinux.yml b/roles/upgrade/tasks/leapp-post-upgrade-selinux.yml index 87bcbd6..04b3cad 100644 --- a/roles/upgrade/tasks/leapp-post-upgrade-selinux.yml +++ b/roles/upgrade/tasks/leapp-post-upgrade-selinux.yml @@ -2,6 +2,7 @@ # TODO: Relocate to validation and compare to previous selinux state. # - name: Ensure there are no SELinux denials # ansible.builtin.shell: > +# export PATH={{ os_release }}; # ausearch -m AVC,USER_AVC -ts boot 2>&1 # register: ausearch_results # changed_when: false diff --git a/roles/upgrade/tasks/leapp-post-upgrade.yml b/roles/upgrade/tasks/leapp-post-upgrade.yml index 9fed21a..4bef7ee 100644 --- a/roles/upgrade/tasks/leapp-post-upgrade.yml +++ b/roles/upgrade/tasks/leapp-post-upgrade.yml @@ -1,7 +1,9 @@ --- # /etc/dnf/dnf.conf is an ini file and could be parsed to check if exclude has value and run this conditionally. - name: Clean dnf exclude list - ansible.builtin.shell: dnf config-manager --save --setopt exclude='' + ansible.builtin.shell: > + export PATH={{ os_release }}; + dnf config-manager --save --setopt exclude='' # leapp 7 to 8 documentation cleans up old kernels - name: Block for RHEL 7 kernel cleanup @@ -17,6 +19,7 @@ - name: Remove weak modules from old kernels ansible.builtin.shell: | + export PATH={{ os_release }} set -o pipefail [ -x /usr/sbin/weak-modules ] && /usr/sbin/weak-modules --remove-kernel {{ item.path | basename }} loop: "{{ old_kernels.files }}" @@ -24,6 +27,7 @@ - name: Remove the old kernels from the boot loader entry ansible.builtin.shell: | + export PATH={{ os_release }} set -o pipefail /bin/kernel-install remove {{ item.path | basename }} {{ item.path }}/vmlinuz loop: "{{ old_kernels.files }}" @@ -54,7 +58,9 @@ var: result - name: Unset subscription-manager release - ansible.builtin.shell: subscription-manager release --unset + ansible.builtin.shell: > + export PATH={{ os_release }}; + subscription-manager release --unset when: leapp_upgrade_type == 'satellite' or leapp_upgrade_type == 'cdn' # TODO: Unset rhui release. @@ -78,6 +84,7 @@ # Only found in RHEL 7 to 8 documentation - name: Old kernels have been removed from the bootloader entry for RHEL 7 to 8 ansible.builtin.shell: | + export PATH={{ os_release }} grubby --info=ALL | grep "\.el7" || echo "Old kernels are not present in the bootloader." register: grubby_check when: ansible_facts.ansible_local.pre_ripu.distribution_major_version | int == 7 diff --git a/roles/upgrade/tasks/leapp-upgrade.yml b/roles/upgrade/tasks/leapp-upgrade.yml index 9f85cb4..3fdd3ef 100644 --- a/roles/upgrade/tasks/leapp-upgrade.yml +++ b/roles/upgrade/tasks/leapp-upgrade.yml @@ -24,6 +24,7 @@ - name: Start Leapp OS upgrade ansible.builtin.shell: > + export PATH={{ os_release }}; set -o pipefail; leapp upgrade {{ leapp_upgrade_opts }} @@ -61,7 +62,9 @@ when: grub_boot_device is defined block: - name: Run grub2-install - ansible.builtin.shell: grub2-install {{ grub_boot_device }} + ansible.builtin.shell: > + export PATH={{ os_release }}; + grub2-install {{ grub_boot_device }} - name: Reboot to pickup grub update ansible.builtin.reboot: diff --git a/roles/upgrade/tasks/redhat-upgrade-tool-post-upgrade.yml b/roles/upgrade/tasks/redhat-upgrade-tool-post-upgrade.yml index 9ac13cf..dd19978 100644 --- a/roles/upgrade/tasks/redhat-upgrade-tool-post-upgrade.yml +++ b/roles/upgrade/tasks/redhat-upgrade-tool-post-upgrade.yml @@ -7,6 +7,7 @@ - name: "Register to post upgrade activation key" ansible.builtin.shell: > + export PATH={{ os_path }}; subscription-manager register --org="{{ satellite_organization }}" --activationkey="{{ satellite_activation_key_post_leapp }}" diff --git a/roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml b/roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml index 60fb689..94a2a2e 100644 --- a/roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml +++ b/roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml @@ -1,6 +1,8 @@ --- - name: Run preupg --riskcheck - ansible.builtin.shell: preupg --riskcheck + ansible.builtin.shell: > + export PATH={{ os_release }}; + preupg --riskcheck register: preupg changed_when: false failed_when: false @@ -13,6 +15,7 @@ # TODO: Having issues with community.general.redhat_subscription and subscription-manager on RHEL 6. - name: Register to leapp activation key ansible.builtin.shell: > + export PATH={{ os_release }}; subscription-manager register --org_id: "{{ satellite_organization }}" activationkey: "{{ satellite_activation_key_leapp }}" @@ -48,6 +51,7 @@ # --cleanup-post removes Red Hat signed RHEL 6 packages and in theory should be safe. - name: Run redhat-upgrade-tool ansible.builtin.shell: > + export PATH={{ os_release }}; set -o pipefail; redhat-upgrade-tool --network 7.9 --instrepo {{ rhel_7_network_install_repo_url }} --force --cleanup-post 2>&1 | tee -a {{ log_file }}