Merge "Add support to use stow for ensure-python"

This commit is contained in:
Zuul 2020-09-24 08:01:34 +00:00 committed by Gerrit Code Review
commit b7d151c911
4 changed files with 50 additions and 2 deletions

View File

@ -3,14 +3,40 @@ Ensure specified python interpreter and development files are installed
.. note:: This role is only available for Debian based platforms
currently.
There are three ways to install the python interpreter:
1. Using distribution packages: This is the default (``python_use_pyenv`` and
``python_use_stow`` are both false``).
2. Install using ``pyenv``.
3. Install using ``stow``.
.. note:: You cannot use both ``pyenv`` and ``stow`` method for the same job.
That means that ``python_use_pyenv`` and ``python_use_stow``
cannot be set both to ``True`` at the same time.
**Role Variables**
.. zuul:rolevar:: python_version
Optional version of python interpreter to install, such as ``3.7``.
Optional version of python interpreter to install, such as ``3.7``.
.. zuul:rolevar:: python_use_pyenv
:default: False
Whether to optionally use pyenv to install python instead of distro
Whether to optionally use ``pyenv`` to install python instead of distro
packages.
.. zuul:rolevar:: python_use_stow
:default: False
In case you have image with already prepared python versions, for example used the
python-stow-versions element, you can activate them with stow utility
by setting this variable to ``true``.
.. zuul:rolevar:: python_stow_dir
:default: /usr/local/stow
Sets the target directory for stow. This should be the path to the
directory where prepared python packages are located.

View File

@ -1 +1,3 @@
python_use_pyenv: false
python_use_stow: false
python_stow_dir: /usr/local/stow

View File

@ -11,6 +11,7 @@
- python_version is defined
- ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- not python_use_pyenv
- not python_use_stow
package:
name: python{{ python_version }}-dev
state: present
@ -21,3 +22,9 @@
- python_version is defined
- python_use_pyenv
include_tasks: pyenv.yaml
- name: Activate python using stow
when:
- python_version is defined
- python_use_stow
include_tasks: stow.yaml

View File

@ -0,0 +1,13 @@
- name: Get stow environments
find:
paths: "{{ python_stow_dir }}"
recurse: no
file_type: directory
register: stow_envs
- name: Activate stow
command: "stow -d {{ python_stow_dir }} -S {{ zj_stow_env | basename }}"
loop: "{{ stow_envs.files | map(attribute='path') | unique }}"
loop_control:
loop_var: zj_stow_env
when: python_version in item