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)
This commit is contained in:
Michal Nasiadka 2024-08-08 17:48:24 +02:00
parent 8e3f4fa81b
commit 0264462a4d
4 changed files with 44 additions and 5 deletions

View File

@ -3,7 +3,7 @@
docker_sdk_packages:
- "python3-setuptools"
- "python3-pip"
- "{% if ansible_facts.distribution_release == 'bookworm' and virtualenv is none %}python3-docker{% endif %}"
- "{% if docker_sdk_python_externally_managed | default(false) and virtualenv is none %}python3-docker{% endif %}"
# List of Python packages to install via Pip.
# NOTE(mnasiadka) docker 3.0.0 is in kolla-ansible requirements

View File

@ -1,4 +1,23 @@
---
- 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 }}"
@ -18,7 +37,7 @@
become_user: "{{ docker_sdk_virtualenv_owner }}"
when: virtualenv is not none
- name: Install docker SDK for python
- name: Install docker SDK for python using pip
pip:
name: "{{ docker_sdk_pip_packages }}"
executable: "{{ virtualenv is none | ternary('pip3', omit) }}"
@ -28,4 +47,4 @@
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 (ansible_facts.distribution_release == "bookworm" and virtualenv is none)
when: not (docker_sdk_python_externally_managed | default(false) and virtualenv is none)

View File

@ -3,7 +3,7 @@
podman_sdk_packages:
- "python3-setuptools"
- "python3-pip"
- "{% if ansible_facts.distribution_release == 'bookworm' and virtualenv is none %}python3-podman{% endif %}"
- "{% if podman_sdk_python_externally_managed | default(false) and virtualenv is none %}python3-podman{% endif %}"
# List of Python packages to install via Pip.
# NOTE(kevko) podman 4.7.0 is built in debian as apt package, so..

View File

@ -1,4 +1,23 @@
---
- 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 podman_sdk_python_externally_managed fact
set_fact:
podman_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: Configure osbpo apt repository
block:
- name: Ensure apt sources list directory exists
@ -44,6 +63,7 @@
update_cache: true
when:
- ansible_facts.distribution == 'Debian'
- podman_sdk_python_externally_managed | default(false)
- virtualenv is none
become: True
@ -76,4 +96,4 @@
virtualenv_command: "{{ virtualenv is none | ternary(omit, 'python' ~ host_python_version ~ ' -m venv') }}"
become: true
become_user: "{{ virtualenv is none | ternary(omit, podman_sdk_virtualenv_owner) }}"
when: not (ansible_facts.distribution_release == "bookworm" and virtualenv is none)
when: not (podman_sdk_python_externally_managed | default(false) and virtualenv is none)