Rhel 7-> 8 upgrade

Hello all,

Upgrading from Rhel7-> 8 using ansible. In the pre upgrade task I performed few checks like space check and yum update and subscription-manager registration. No issues in the beginning tasks…

But when performing below task post reboot task Shell:
Yum clean all
Subscription-manager unsubscribe —all
Subscription-manager clean

It is giving me no such file /usr/bin/python

Before running the job In RHEl 7 the python version was pointing to

Python2 /usr/bin/python-> /etc/alternatives/python /etc/alternatives/python → /usr/bin/python2

but after the above task is executed somehow it is changing to
/usr/bin/python-> /etc/alternatives/python /etc/alternatives/python → /usr/bin/python3

When I performed manually the task command there is no issue … could you pls suggest…

Regards
PD

That is a Rhel7 to RHEL 8 change. The default python in REHL7 is Python 2.7 while RHEL 8 is python3.6. I would also consider moving the subscription tasks to community.general.redhat_subscription module. That is should automatically change python version, but you may need to disconnect and reconnect to update the user environment.

Thank you the problem is before updating to Rhel 8 also when it reboots in the last below task (line#99) the alternatives is updating to python3 link which is not present . Do you suggest to use subscription module in line#79 instead of shell?

  1. name: Get root volume size

  2. set_fact:

  3. root_size: “{{ (ansible_mounts |selectattr(‘mount’, ‘equalto’, ‘/’) | list)[0].size_total }}”

    • name: Get root volume free size
  4. set_fact:

  5. root_available: “{{ (ansible_mounts |selectattr(‘mount’, ‘equalto’, ‘/’) | list)[0].size_available }}”

    • name: root filesystem expansion
  6. block:

    • name: Calculte required additional root space
  7. set_fact:

  8. root_reqd: “{{ ((root_size | int + (4294967296 - root_available | int)) / 1024 / 1024) | int }}”

    • name: Resize root filesystem to {{ root_reqd }}MB
  9. lvol:

  10. vg: rootvg

  11. lv: LogVol00

  12. size: “{{ root_reqd }}M”

  13. resizefs: true

  14. when: root_available | int < 4294967296

    • name: Get /var volume size
  15. set_fact:

  16. var_size: “{{ (ansible_mounts |selectattr(‘mount’, ‘equalto’, ‘/var’) | list)[0].size_total }}”

    • name: Get /var volume free size
  17. set_fact:

  18. var_available: “{{ (ansible_mounts |selectattr(‘mount’, ‘equalto’, ‘/var’) | list)[0].size_available }}”

    • name: /var filesystem expansion
  19. block:

    • name: Calculte required additional var space
  20. set_fact:

  21. var_reqd: “{{ ((var_size | int + (5368709120 - var_available | int)) / 1024 / 1024) | int }}”

    • name: Resize /var filesystem to {{ var_reqd }}MB
  22. lvol:

  23. vg: rootvg

  24. lv: LogVol03

  25. size: “{{ var_reqd }}M”

  26. resizefs: true

  27. when: var_available | int < 5368709120

  28. Pre-upgrade tasks

    • name: Remove unwanted packages
  29. yum:

  30. name: “{{ item }}”

  31. state: absent

  32. loop: “{{ remove_rpms }}”

    • name: Remove unwanted data
  33. file:

  34. path: “{{ item }}”

  35. state: absent

  36. loop: “{{ remove_files }}”

    • name: Get contents of /usr/openv/ folder
  37. find:

  38. paths: /usr/openv/

  39. file_type: any

  40. register: openv

    • name: Remove contents of /usr/openv/ folder
  41. file:

  42. path: “{{ item.path }}”

  43. state: absent

  44. loop: “{{ openv.files }}”

  45. loop_control:

  46. label: “{{ item.path }}”

    • name: Subscribe to RHEL7 Repo
  47. shell: |

  48. yum clean all

  49. subscription-manager register --org=“Xxxxx” --activationkey=“rhel7-prod” --force

    • name: Yum update
  50. yum:

  51. state: latest

    • name: Backup /etc/fstab file
  52. copy:

  53. src: /etc/fstab

  54. dest: /etc/fstab.PreUpgrade

  55. remote_src: yes

  56. force: false

    • name: Remove non system entries from /etc/fstab
  57. shell: |

  58. cat /etc/fstab|egrep -w ‘/ |/opt |/boot |/tmp |/var |swap |^#’ > /tmp/fstab

  59. /bin/cp /tmp/fstab /etc/fstab

    • debug: var=ansible_python_version
    • name: Reboot server
  60. reboot:

  61. reboot_timeout: 3600

    • debug: var=ansible_python_version
  62. Leapp pre-upgrade tasks

    • name: Unsubscribe from satellite
  63. shell: |

  64. yum clean all

  65. subscription-manager unsubscribe --all

  66. subscription-manager clean

Regards

Lines 77-79 and 107-110 would be the ones I would change. Using Modules is cleaner, and more predictable typically.

Have you confirmed the user specific settings for the ansible user on the remote host? The per user alternative may be different than the system.

Thank you… I ll try to use the modules instead.
And we run ansible with the root user …
also when I rebooting my server manually the default python link is getting updated to pyhon3

Now I raised the issue to RH let’s see what comes up

Thanks again

Well, yes. A lot of system tools, especially rpm itself, got updated
to use python3 and the updated /usr/bin/python link because python2 is
*obsolete* and no longer supported. Frankly, by the time you work out
trying nto do the update in place, you could make a full backup of the
whole OS to some separate location, done a clean installation, and
recovered necessary configurations from the backup.

Doing that kind of remotely managed update as a remotely triggered
operation is.... pretty dangerous. There are a lot of ways around it.
My favorite, from long before ansible, was to pick an underused
partition, copy everything I might care about into *that*, and
completely re-install the OS with optional re-partitioning and file
system creation with newer tools along the way.