Fix: Install python 3.10.x on CentOS 7 55/72655/4
authorAnil Belur <abelur@linuxfoundation.org>
Sun, 18 Feb 2024 06:47:05 +0000 (16:47 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 20 Feb 2024 12:30:20 +0000 (22:30 +1000)
Python 3.10.x is a pre-requiste for the ansible version 9.2.0
used fro the packer jobs. However the version of python 3.10.x
requires openssl11 libs and headers to be installed so that pyenv
install builds the required runtime dependencies.

ERROR: "ModuleNotFoundErrorr No module named '_ssl'"
"The Python ssl extension was not compiled. Missing the OpenSSL lib?"

Ref: https://github.com/pyenv/pyenv/wiki/Common-build-problems
Change-Id: Ib1c51882f057b7cf2c3a3c9307d524c9cf45b3a2
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
tasks/main.yml
vars/RedHat.yml

index 5db66c9..ca7b6cf 100644 (file)
       ansible.builtin.command: "dnf install compat-openssl10* -y"
       when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '8'
 
+    - name: Install SSL dependencies required pyenv for python 3.10.x for CentOS 7  # noqa no-changed-when
+      when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7'
+      ansible.builtin.yum:
+        name:
+          - openssl11
+          - openssl11-devel
+        update_cache: yes
+        state: present
+
 - name: Install Python 3.x versions via pyenv
   become: true
   environment:
     - name: 'Install Python {{ pyenv_cmd }}'  # noqa no-changed-when
       ansible.builtin.command: 'pyenv install -s {{ item }}'
       loop: '{{ python_versions }}'
+    - name: 'Install Python on CentOS 7 {{ python310_version }}'  # noqa no-changed-when
+      ansible.builtin.shell: |
+        CPPFLAGS=$(pkg-config --cflags openssl11) LDFLAGS=$(pkg-config --libs openssl11) pyenv install -s {{ python310_version }}
+      when:
+        - ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7'
     - name: 'Install Python {{ python310_version }}'  # noqa no-changed-when
       ansible.builtin.command: pyenv install -s {{ python310_version }}
       when:
         - (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '18.04') or
-          (ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '8')
+          (ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7')
     - name: 'Install Python {{ python311_version }}'  # noqa no-changed-when
       ansible.builtin.command: pyenv install -s {{ python311_version }}
       when:
index 56e04c8..b3c8a33 100644 (file)
@@ -11,3 +11,5 @@ python_packages_distro:
   - python36-pip
   - python36-setuptools
   - python36-virtualenv
+  - openssl11
+  - openssl11-devel