# Rhel 7-\> 8 upgrade

**URL:** <https://forum.ansible.com/t/rhel-7-8-upgrade/38696>\
**Category:** Ansible Project\
**Tags:** rhel, ansible-project\
**Created:** [February 21, 2024, 11:06am UTC](https://forum.ansible.com/t/rhel-7-8-upgrade/38696 "2024-02-21T11:06:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [February 21, 2024, 11:06am UTC](https://forum.ansible.com/t/rhel-7-8-upgrade/38696/1 "2024-02-21T11:06:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Evan\_Hisey](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@Evan\_Hisey](https://forum.ansible.com/u/Evan_Hisey)\
**Post date:** [February 21, 2024, 7:59pm UTC](https://forum.ansible.com/t/rhel-7-8-upgrade/38696/2 "2024-02-21T19:59:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [February 22, 2024, 4:45am UTC](https://forum.ansible.com/t/rhel-7-8-upgrade/38696/3 "2024-02-22T04:45:46Z")

</div>

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 }}”

4. 
5. 
  - name: Get root volume free size

6. set\_fact:

7. root\_available: “{{ (ansible\_mounts |selectattr(‘mount’, ‘equalto’, ‘/’) | list)[0].size\_available }}”

8. 
9. 
  - name: root filesystem expansion

10. block:

11. 
12. 
  - name: Calculte required additional root space

13. set\_fact:

14. root\_reqd: “{{ ((root\_size | int + (4294967296 - root\_available | int)) / 1024 / 1024) | int }}”

15. 
16. 
  - name: Resize root filesystem to {{ root\_reqd }}MB

17. lvol:

18. vg: rootvg

19. lv: LogVol00

20. size: “{{ root\_reqd }}M”

21. resizefs: true

22. 
23. when: root\_available | int \< 4294967296

24. 
25. 
  - name: Get /var volume size

26. set\_fact:

27. var\_size: “{{ (ansible\_mounts |selectattr(‘mount’, ‘equalto’, ‘/var’) | list)[0].size\_total }}”

28. 
29. 
  - name: Get /var volume free size

30. set\_fact:

31. var\_available: “{{ (ansible\_mounts |selectattr(‘mount’, ‘equalto’, ‘/var’) | list)[0].size\_available }}”

32. 
33. 
  - name: /var filesystem expansion

34. block:

35. 
36. 
  - name: Calculte required additional var space

37. set\_fact:

38. var\_reqd: “{{ ((var\_size | int + (5368709120 - var\_available | int)) / 1024 / 1024) | int }}”

39. 
40. 
  - name: Resize /var filesystem to {{ var\_reqd }}MB

41. lvol:

42. vg: rootvg

43. lv: LogVol03

44. size: “{{ var\_reqd }}M”

45. resizefs: true

46. 
47. when: var\_available | int \< 5368709120

48. 
49. 
#### Pre-upgrade tasks
50. 
  - name: Remove unwanted packages

51. yum:

52. name: “{{ item }}”

53. state: absent

54. loop: “{{ remove\_rpms }}”

55. 
56. 
  - name: Remove unwanted data

57. file:

58. path: “{{ item }}”

59. state: absent

60. loop: “{{ remove\_files }}”

61. 
62. 
  - name: Get contents of /usr/openv/ folder

63. find:

64. paths: /usr/openv/

65. file\_type: any

66. register: openv

67. 
68. 
  - name: Remove contents of /usr/openv/ folder

69. file:

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

71. state: absent

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

73. loop\_control:

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

75. 
76. 
  - name: Subscribe to RHEL7 Repo

77. shell: |

78. yum clean all

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

80. 
81. 
  - name: Yum update

82. yum:

83. state: latest

84. 
85. 
  - name: Backup /etc/fstab file

86. copy:

87. src: /etc/fstab

88. dest: /etc/fstab.PreUpgrade

89. remote\_src: yes

90. force: false

91. 
92. 
  - name: Remove non system entries from /etc/fstab

93. shell: |

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

95. /bin/cp /tmp/fstab /etc/fstab

96. 
97. 
  - debug: var=ansible\_python\_version

98. 
99. 
  - name: Reboot server

100. reboot:

101. reboot\_timeout: 3600

102. 
103. 
  - debug: var=ansible\_python\_version

104. 
105. 
#### Leapp pre-upgrade tasks
106. 
  - name: Unsubscribe from satellite

107. shell: |

108. yum clean all

109. subscription-manager unsubscribe --all

110. subscription-manager clean

Regards

---

<div class="post-metadata">

**Author:** ![Evan\_Hisey](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@Evan\_Hisey](https://forum.ansible.com/u/Evan_Hisey)\
**Post date:** [February 22, 2024, 9:18pm UTC](https://forum.ansible.com/t/rhel-7-8-upgrade/38696/4 "2024-02-22T21:18:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [February 23, 2024, 3:13am UTC](https://forum.ansible.com/t/rhel-7-8-upgrade/38696/5 "2024-02-23T03:13:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [February 25, 2024, 3:28pm UTC](https://forum.ansible.com/t/rhel-7-8-upgrade/38696/6 "2024-02-25T15:28:01Z")

</div>

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.
