Michal Nasiadka 0264462a4d docker/podman_sdk: Install sdk from deb when python externally managed
Since we're adding Ubuntu 24.04 that has python3.12 - we need to
install python3-docker/podman also there - future proof solution
is to check for existence of EXTERNALLY-MANAGED file.

Change-Id: Ibd2ab4379aac9cccf49d98b6bf3c12526eacdbd1
(cherry picked from commit 2ee3e850f13a0bcbe2b6a5e9d85847c13588bb26)
2024-09-20 11:53:29 +00:00

51 lines
2.2 KiB
YAML

---
- name: Handling for Python3.10+ externally managed environments
block:
- name: Get Python
ansible.builtin.command: "{{ ansible_facts.python.executable }} -c 'import sysconfig; print(sysconfig.get_path(\"stdlib\", sysconfig.get_default_scheme()))'"
changed_when: false
register: python_default_scheme_path
- name: Check if Python environment is externally managed
ansible.builtin.stat:
path: "{{ python_default_scheme_path.stdout }}/EXTERNALLY-MANAGED"
register: python_externally_managed
- name: Set docker_sdk_python_externally_managed fact
set_fact:
docker_sdk_python_externally_managed: true
when: python_externally_managed.stat.exists
when: ansible_facts.python.version.major == 3 and ansible_facts.python.version.minor >= 10
- name: Install packages
package:
name: "{{ docker_sdk_packages | select | list }}"
cache_valid_time: "{{ apt_cache_valid_time if ansible_facts.os_family == 'Debian' else omit }}"
update_cache: "{{ True if ansible_facts.os_family == 'Debian' else omit }}"
state: present
become: true
- name: Install latest pip in the virtualenv
pip:
# NOTE(hrw) pip 19.3 is first version complaining about being run with Python 2
name: pip>19.3
virtualenv: "{{ virtualenv }}"
virtualenv_site_packages: "{{ virtualenv_site_packages }}"
virtualenv_command: "python{{ host_python_version }} -m venv"
become: true
become_user: "{{ docker_sdk_virtualenv_owner }}"
when: virtualenv is not none
- name: Install docker SDK for python using pip
pip:
name: "{{ docker_sdk_pip_packages }}"
executable: "{{ virtualenv is none | ternary('pip3', omit) }}"
extra_args: "{% if docker_sdk_upper_constraints_file %}-c {{ docker_sdk_upper_constraints_file }}{% endif %}"
virtualenv: "{{ virtualenv is none | ternary(omit, virtualenv) }}"
virtualenv_site_packages: "{{ virtualenv is none | ternary(omit, virtualenv_site_packages) }}"
virtualenv_command: "{{ virtualenv is none | ternary(omit, 'python' ~ host_python_version ~ ' -m venv') }}"
become: true
become_user: "{{ virtualenv is none | ternary(omit, docker_sdk_virtualenv_owner) }}"
when: not (docker_sdk_python_externally_managed | default(false) and virtualenv is none)