diff --git a/roles/ensure-python/README.rst b/roles/ensure-python/README.rst index 6488331cd..efb74f48f 100644 --- a/roles/ensure-python/README.rst +++ b/roles/ensure-python/README.rst @@ -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. diff --git a/roles/ensure-python/defaults/main.yaml b/roles/ensure-python/defaults/main.yaml index a34eef7e1..80779118e 100644 --- a/roles/ensure-python/defaults/main.yaml +++ b/roles/ensure-python/defaults/main.yaml @@ -1 +1,3 @@ python_use_pyenv: false +python_use_stow: false +python_stow_dir: /usr/local/stow diff --git a/roles/ensure-python/tasks/main.yaml b/roles/ensure-python/tasks/main.yaml index 9d70ffbbf..fbcf4032e 100644 --- a/roles/ensure-python/tasks/main.yaml +++ b/roles/ensure-python/tasks/main.yaml @@ -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 diff --git a/roles/ensure-python/tasks/stow.yaml b/roles/ensure-python/tasks/stow.yaml new file mode 100644 index 000000000..8d41fdf36 --- /dev/null +++ b/roles/ensure-python/tasks/stow.yaml @@ -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