--- - name: Configure osbpo apt repository when: - ansible_facts.distribution == 'Debian' - docker_sdk_python_externally_managed | default(false) - virtualenv is none block: - name: Ensure apt sources list directory exists file: path: /etc/apt/sources.list.d state: directory recurse: true become: true - name: Ensure apt keyrings directory exists file: path: /etc/apt/keyrings state: directory recurse: true become: true - name: Install osbpo apt gpg key template: src: osbpo_pubkey.gpg.j2 dest: /etc/apt/keyrings/osbpo.asc mode: "0644" become: true - name: Enable osbpo apt repository apt_repository: repo: "{{ docker_sdk_osbpo_apt_repo }}" filename: osbpo become: true - 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: Check if virtualenv is a directory stat: path: "{{ virtualenv }}" register: virtualenv_stat when: virtualenv is not none and virtualenv | length > 0 # NOTE(kevko) Packaging needs to be installed before ansible's pip module is used # This is in case user created venv manually - name: Check if packaging is already installed command: "{{ virtualenv }}/bin/pip show packaging" become: true become_user: "{{ docker_sdk_virtualenv_owner }}" register: packaging_installed failed_when: false changed_when: false check_mode: false when: - virtualenv is not none - virtualenv | length > 0 - virtualenv_stat.stat.isdir is defined - virtualenv_stat.stat.isdir - name: Install packaging into virtualenv command: "{{ virtualenv }}/bin/python -m pip install packaging" become: true become_user: "{{ docker_sdk_virtualenv_owner }}" check_mode: false changed_when: packaging_installed.rc != 0 when: - virtualenv is not none - virtualenv | length > 0 - virtualenv_stat.stat.isdir is defined - virtualenv_stat.stat.isdir - packaging_installed.rc != 0 - name: Install latest pip and packaging in the virtualenv pip: # NOTE(hrw) pip 19.3 is first version complaining about being run with Python 2 name: - "pip>19.3" - "packaging" virtualenv: "{{ virtualenv }}" virtualenv_site_packages: "{{ virtualenv_site_packages }}" virtualenv_command: "{{ ansible_facts.python.executable }} -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_core_pip_packages + docker_sdk_additional_pip_packages }}" executable: "{{ (virtualenv is none) | ternary(ansible_facts.python.executable | regex_replace('python(\\d+(\\.\\d+)?)$', 'pip\\1'), 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, ansible_facts.python.executable ~ ' -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)