zuul-jobs/test-playbooks/ensure-poetry.yaml
Aurelio Jargas 524b7e7b95 Add ensure-poetry role
Poetry (https://python-poetry.org) is not declared as a dependency for a
Python project, it must be available somehow in the system. This role
installs it if missing.

- Latest version is installed, unless `ensure_poetry_version` is
  informed.

- The installed executable path is set as the `poetry_executable` fact.

- The `/usr/local/bin/poetry` symlink can also be created if
  `ensure_poetry_global_symlink: true`.

This new role is basically a copy of the `ensure-nox` role with the
symlink creation snippet taken from the `ensure-tox` role.

The commit adding `ensure-nox` (77b1b24) has been taken as an example of
the necessary changes when adding a new role.

Change-Id: I5592d38d415a9d74055348406653b69f110541ae
2024-07-02 08:00:55 -07:00

36 lines
1.4 KiB
YAML

- hosts: all
name: Test ensure-poetry installs into user environment
tasks:
- name: Verify poetry is not installed
command: "poetry --version"
register: result
failed_when: result.rc == 0
- name: Run ensure-poetry with poetry not installed
include_role:
name: ensure-poetry
- name: Verify ensure_poetry_executable is set
assert:
that:
- ensure_poetry_executable == ansible_user_dir + '/.local/poetry/bin/poetry'
- name: Verify poetry is installed
command: "{{ ensure_poetry_executable }} --version"
register: result
failed_when: result.rc != 0
- hosts: all
name: Test ensure-poetry when ensure_poetry_executable is set to an already installed poetry
tasks:
- name: Create a virtualenv
command: '{{ ensure_pip_virtualenv_command }} {{ ansible_user_dir }}/poetry-venv'
- name: Install poetry to local venv
command: '{{ ansible_user_dir }}/poetry-venv/bin/pip install poetry'
- name: Run ensure-poetry pointing to an already installed poetry
include_role:
name: ensure-poetry
vars:
ensure_poetry_executable: "{{ ansible_user_dir }}/poetry-venv/bin/poetry"
- name: Verify ensure_poetry_executable is set to the virtualenv poetry
assert:
that:
- ensure_poetry_executable == ansible_user_dir + '/poetry-venv/bin/poetry'