[ansible-project] Rhel 7-> 8 upgrade

338 views
Skip to first unread message

Prady A

unread,
Feb 21, 2024, 6:07:22 AM2/21/24
to ansible...@googlegroups.com
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

Evan Hisey

unread,
Feb 21, 2024, 3:00:17 PM2/21/24
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEuB3ApKqRhVmC3DzvX-EpBpebQCk5EKEq3CWkRv_uGH1ni50A%40mail.gmail.com.

Prady A

unread,
Feb 21, 2024, 11:46:17 PM2/21/24
to ansible...@googlegroups.com
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 

Evan Hisey

unread,
Feb 22, 2024, 4:18:34 PM2/22/24
to ansible...@googlegroups.com
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.

Prady A

unread,
Feb 22, 2024, 10:13:48 PM2/22/24
to ansible...@googlegroups.com
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

On Fri, 23 Feb 2024 at 06:18, Evan Hisey <ehi...@gmail.com> wrote:
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Nico Kadel-Garcia

unread,
Feb 25, 2024, 10:28:31 AM2/25/24
to ansible...@googlegroups.com
On Thu, Feb 22, 2024 at 10:13 PM Prady A <pradyu...@gmail.com> wrote:
>
> 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.
Reply all
Reply to author
Forward
0 new messages