Skip to content

Commit

Permalink
Fix: Update python-install to build with latest
Browse files Browse the repository at this point in the history
Modernize the molecule test formats and update the role.
Update tox and pre-commit dependencies to build with latest
versions of ansible and molecule.

Signed-off-by: Anil Belur <[email protected]>
Change-Id: Ia22bb1e41bad236bd3daea25a9f66fe7157675ee
Signed-off-by: Anil Belur <[email protected]>
  • Loading branch information
askb committed Feb 10, 2024
1 parent 8fd228b commit 8f3f2c5
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 43 deletions.
4 changes: 1 addition & 3 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ rules:
max-spaces-inside: 1
level: error
line-length: disable
# NOTE(retr0h): Templates no longer fail this lint rule.
# Uncomment if running old Molecule templates.
# truthy: disable
truthy: disable

ignore: |
.tox/
5 changes: 3 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
pyenv_version: v2.3.3
pyenv_version: v2.3.35
python39_version: 3.9.13
python38_version: 3.8.13
python310_version: 3.10.6
python310_version: 3.10.13
python311_version: 3.11.7

python_versions:
- '{{ python39_version }}'
Expand Down
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ galaxy_info:
versions:
- 7
- 8
- 9

- name: Ubuntu
versions:
- bionic
- focal
- jammy

galaxy_tags:
- pyenv
Expand Down
6 changes: 2 additions & 4 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ dependency:
name: galaxy
driver:
name: docker
lint: |
yamllint .
ansible-lint tasks/*.yml
platforms:
- name: centos7
image: centos:7
Expand All @@ -15,12 +12,13 @@ platforms:
image: ubuntu:18.04
- name: ubuntu2004
image: ubuntu:20.04
- name: ubuntu2204
image: ubuntu:22.04
provisioner:
name: ansible
scenario:
name: default
test_sequence:
- lint
- destroy
- dependency
- syntax
Expand Down
12 changes: 6 additions & 6 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
hosts: all
gather_facts: true
tasks:
- rpm_key:
- ansible.builtin.rpm_key:
state: present
key: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8
when: ansible_os_family == 'RedHat'
become: true
- name: Install Fedora EPEL repo
yum:
ansible.builtin.yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm
state: present
when: ansible_os_family == 'RedHat'
become: true

- name: Update APT cache
apt:
ansible.builtin.package:
update_cache: yes
when: ansible_distribution == 'Ubuntu'
become: true

- name: Install Git
package: name=git state=present
ansible.builtin.package: name=git state=present

- name: Install Python compile dependencies
yum:
ansible.builtin.yum:
name:
- bzip2-devel
- gcc
Expand All @@ -36,7 +36,7 @@
become: true

- name: Install Python compile dependencies
apt:
ansible.builtin.package:
name:
- libbz2-dev
- gcc
Expand Down
42 changes: 24 additions & 18 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
---
- name: Include distro specific variables
include_vars: "{{ item }}"
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml'
- '{{ ansible_distribution }}.yml'
- '{{ ansible_os_family }}.yml'

- name: Install Python
package:
ansible.builtin.package:
name: '{{ python_packages }}'
state: present
become: true

- name: Pre-set python versions required for pyenv global command
block:
- name: "Set Python version on Ubuntu >= 18.04 or CentOS 7"
set_fact:
ansible.builtin.set_fact:
pyenv_cmd: "{{ python_versions | join(' ') }}"
when:
- (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '18.04') or
(ansible_distribution == 'CentOS')

- name: "Set Python 3.10 on CentOS >= 8 or on Ubuntu >= 18/04"
set_fact:
pyenv_cmd: "{{ (python_versions | join(' ')) ~ ' ' ~ python310_version }}"
ansible.builtin.set_fact:
pyenv_cmd: "{{ (python_versions | join(' ')) ~ ' ' ~ python310_version ~ ' ' ~ python311_version }}"
when:
- (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '18.04') or
(ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '8')
Expand All @@ -33,37 +33,43 @@
# The compat-openssl libs are available only for CentOS8, so python 3.10x will
# be available for >= CentOS8
- name: Install SSL dependencies required pyenv for python 3.10.x
become: true
block:
- name: Update SSL dependencies for CentOS
command: "dnf install compat-openssl10* -y"
- name: Update SSL dependencies for CentOS # noqa no-changed-when
ansible.builtin.command: "dnf install compat-openssl10* -y"
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '8'
become: true

- name: Install Python 3.x versions via pyenv
become: true
environment:
PYENV_ROOT: /opt/pyenv
PATH: '/opt/pyenv/bin:{{ ansible_env.PATH }}'
PYTHON38_VERSION: '{{ python38_version }}'
PYTHON39_VERSION: '{{ python39_version }}'
PYTHON310_VERSION: '{{ python310_version }}'
PYTHON311_VERSION: '{{ python311_version }}'
block:
- name: 'Install pyenv {{ pyenv_version }}'
git:
ansible.builtin.git:
repo: https://github.com/pyenv/pyenv.git
dest: /opt/pyenv
version: '{{ pyenv_version }}'
- name: 'Install Python {{ pyenv_cmd }}'
command: 'pyenv install -s {{ item }}'
- name: 'Install Python {{ pyenv_cmd }}' # noqa no-changed-when
ansible.builtin.command: 'pyenv install -s {{ item }}'
loop: '{{ python_versions }}'
- name: 'Install Python {{ python310_version }}'
command: 'pyenv install -s {{ python310_version }}'
- 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')
- name: 'Set the required python 3.x versions using pyenv on Ubuntu'
command: 'pyenv global system {{ pyenv_cmd }}'
- name: 'Install Python {{ python311_version }}' # noqa no-changed-when
ansible.builtin.command: pyenv install -s {{ python311_version }}
when:
- (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '18.04') or
(ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '8')
- name: 'Set the required python 3.x versions using pyenv on Ubuntu' # noqa no-changed-when
ansible.builtin.command: 'pyenv global system {{ pyenv_cmd }}'
when: ansible_distribution == 'Ubuntu'
- name: 'Set the required python 3.x versions using pyenv on CentOS'
command: 'pyenv global {{ pyenv_cmd }}'
- name: 'Set the required python 3.x versions using pyenv on CentOS' # noqa no-changed-when
ansible.builtin.command: 'pyenv global {{ pyenv_cmd }}'
when: ansible_distribution == 'CentOS'
become: true
29 changes: 20 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@
minversion = 1.6
envlist =
molecule,
pre-commit
pre-commit,
lint
skipsdist=true

[testenv:molecule]
basepython = python3
deps =
ansible~=2.9.6
ansible-lint~=4.2.0
detox~=0.18
ansible
docker
yamllint
molecule~=3.0.8
molecule[docker]
pytest~=5.4.0
molecule
molecule-docker
passenv = *
commands =
./molecule.sh
allowlist_externals =
./molecule.sh

[testenv:pre-commit]
allowlist_externals =
/bin/sh
deps = pre-commit
allowlist_externals = /bin/sh
passenv = HOME
commands =
pre-commit run --all-files --show-diff-on-failure
/bin/sh -c 'if ! git config --get user.name > /dev/null; then \
Expand All @@ -44,3 +43,15 @@ commands =
/bin/sh -c "if [ -f .git/REMOVE_USEREMAIL ]; then \
git config --global --unset user.email; \
rm -f .git/REMOVE_USEREMAIL; fi"

[testenv:lint]
basepython = python310
deps =
ansible-lint
yamllint
commands =
/bin/bash -c "ansible-lint tasks/*.yml"
yamllint .
allowlist_externals =
/bin/bash
yamllint
13 changes: 13 additions & 0 deletions vars/Ubuntu-22.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
python_packages_distro:
- libffi-dev
- libssl-dev
- python-is-python3
- python3
- python3
- python3-dev
- python3-openssl
- python3-pip
- python3-setuptools
- python3-virtualenv
- python3-venv

0 comments on commit 8f3f2c5

Please sign in to comment.