Skip to content

Commit

Permalink
Fix: Install python 3.10.x on CentOS 7
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
askb committed Feb 20, 2024
1 parent 8f3f2c5 commit a86f063
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
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:
Expand All @@ -57,11 +66,16 @@
- 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:
Expand Down
2 changes: 2 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ python_packages_distro:
- python36-pip
- python36-setuptools
- python36-virtualenv
- openssl11
- openssl11-devel

0 comments on commit a86f063

Please sign in to comment.