Michal Nasiadka c4a1dcd3c7 Adapt code in preparation for ansible-lint bump
Rename True/False to true/false
Fix permissions values

Change-Id: I75be15fd24aeedf54bb22b9744bc0ee498a62645
2024-10-09 11:27:12 +02:00

101 lines
3.6 KiB
YAML

---
- name: Handling for Python3.10+ externally managed environments
block:
- name: Get Python
ansible.builtin.command:
cmd: "{{ 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
file:
path: /etc/apt/sources.list.d
state: directory
recurse: true
- name: Ensure apt keyrings directory exists
file:
path: /etc/apt/keyrings
state: directory
recurse: true
- name: Install osbpo apt gpg key
template:
src: osbpo_pubkey.gpg.j2
dest: /etc/apt/keyrings/osbpo.asc
mode: "0644"
- name: Ensure old osbpo apt repository absent
file:
path: /etc/apt/sources.list.d/osbpo.list
state: absent
# TODO(mmalchuk): replace with ansible.builtin.deb822_repository module
# when all stable releases moves to the ansible-core >= 2.15
- name: Enable osbpo apt repository
copy:
dest: /etc/apt/sources.list.d/docker.sources
content: |
# Ansible managed
Types: deb
URIs: {{ podman_sdk_osbpo_apt_url }}
Suites: bookworm-bobcat-backports-nochange
Components: main
Signed-by: /etc/apt/keyrings/osbpo.asc
mode: "0644"
- name: Update the apt cache
apt:
update_cache: true
when:
- ansible_facts.distribution == 'Debian'
- podman_sdk_python_externally_managed | default(false)
- virtualenv is none
become: true
- name: Install packages
package:
name: "{{ podman_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: "{{ podman_sdk_virtualenv_owner }}"
when: virtualenv is not none
- name: Install podman SDK for python
pip:
name: "{{ podman_sdk_pip_packages }}"
executable: "{{ virtualenv is none | ternary('pip3', omit) }}"
extra_args: "{% if podman_sdk_upper_constraints_file %}-c {{ podman_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, podman_sdk_virtualenv_owner) }}"
when: not (podman_sdk_python_externally_managed | default(false) and virtualenv is none)