diff --git a/molecule/resources/tests/test_default.py b/molecule/resources/tests/test_default.py index 7b0cefe..1059926 100644 --- a/molecule/resources/tests/test_default.py +++ b/molecule/resources/tests/test_default.py @@ -7,8 +7,8 @@ def test_virtualenv(host): venv = '/opt/test/python3-virtualenv' - host.check_output(venv + '/bin/python --version').startswith('Python 3.12') - host.check_output(venv + '/bin/pip --version').startswith('Python 3.12') + assert host.check_output(venv + '/bin/python --version').startswith('Python 3.12') + assert host.check_output(venv + '/bin/pip --version').startswith('pip 2') assert host.file(venv + '/bin/python').is_file assert host.file(venv + '/bin/python3').is_file assert host.file(venv + '/bin/pip').is_file diff --git a/tasks/python-venv_installation.yml b/tasks/python-venv_installation.yml index 43ac41b..a5ccc2e 100644 --- a/tasks/python-venv_installation.yml +++ b/tasks/python-venv_installation.yml @@ -1,4 +1,3 @@ ---- - name: python venv | check if the {{ env_name }} dir exists stat: @@ -71,3 +70,33 @@ src: "{{ virtualenv_basedir }}/venv-{{ python_version }}" dest: "{{ virtualenv_basedir }}/{{ env_name }}" state: link + +## check the installed python version +- name: check the installed python version + command: "{{ virtualenv_basedir }}/{{ env_name }}/bin/python{{ python_version }} --version" + changed_when: false + register: installed_pythonversion + +- ansible.builtin.set_fact: + int_py_version: "{{ installed_pythonversion.stdout.split('.')[-1] | int }}" + +# patch for the pip issue + +- name: update the pip version if the python version is less than 3.11.18 or python 3.12.16 + become: true + command: "{{ virtualenv_basedir }}/{{ env_name }}/bin/python{{ python_version }} -m pip install 'pip @ https://files.pythonhosted.org/packages/3f/06/3e4420302363fbb71be3c7f35ce042f54bfca330e3e66b3a2e3c4cca579f/pip-26.2.2-py3-none-any.whl#sha256=fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70'" + changed_when: false + when: "(python_version == '3.12' and (int_py_version| int) < 16) or (python_version == '3.11' and (int_py_version| int) < 18)" + +- name: update the certifi version if the python version is less than 3.11.18 or 3.12.16 + become: true + command: "{{ virtualenv_basedir }}/{{ env_name }}/bin/python{{ python_version }} -m pip install --upgrade 'certifi>=2026.10.19'" + changed_when: false + when: "(python_version == '3.12' and (int_py_version | int) < 16) or (python_version == '3.11' and (int_py_version | int) < 18)" + +- name: update pip and certifi if the python version is equal or grater than 3.11.18 or 3.12.16 + become: true + command: "{{ virtualenv_basedir }}/{{ env_name }}/bin/python{{ python_version }} -m pip install --upgrade pip certifi" + changed_when: false + when: "(python_version == '3.12' and (int_py_version | int) >= 16) or (python_version == '3.11' and (int_py_version | int) >= 18)" +