From 06ad3eef8a512580a1e6b22dc2a334dd3973bc82 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 17 Jun 2020 13:27:36 -0500 Subject: [PATCH] Add option to install tox into a path location We can't do this all the time, because of rootless environments. But sometimes people have root and want to be able to use something from scripts from normal path. Change-Id: I3f57a6108f8f53ebfdd12f04ecb3d8c68c5b4a60 --- roles/ensure-tox/README.rst | 11 +++++++++++ roles/ensure-tox/defaults/main.yaml | 1 + roles/ensure-tox/tasks/main.yaml | 18 ++++++++++++++---- test-playbooks/ensure-tox.yaml | 9 ++++----- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/roles/ensure-tox/README.rst b/roles/ensure-tox/README.rst index 937c0f847..26a79a94b 100644 --- a/roles/ensure-tox/README.rst +++ b/roles/ensure-tox/README.rst @@ -16,6 +16,17 @@ virtual environment for the current user. will be automatically set to `True` to enable a Python 2 installation of `pip`. +.. zuul:rolevar:: ensure_global_symlinks + :default: False + + Install a symlink to the tox executable into ``/usr/local/bin/tox``. + This can be useful when scripts need to be run that expect to find + tox in a more standard location and plumbing through the value + of ``tox_executable`` would be onerous. + + Setting this requires root access, so should only be done in + circumstances where root access is available. + **Output Variables** .. zuul:rolevar:: tox_executable diff --git a/roles/ensure-tox/defaults/main.yaml b/roles/ensure-tox/defaults/main.yaml index 7479455e6..d210ecce0 100644 --- a/roles/ensure-tox/defaults/main.yaml +++ b/roles/ensure-tox/defaults/main.yaml @@ -1,3 +1,4 @@ tox_executable: tox tox_venv_path: '{{ ansible_user_dir }}/.local/tox' tox_prefer_python2: false +ensure_global_symlinks: false diff --git a/roles/ensure-tox/tasks/main.yaml b/roles/ensure-tox/tasks/main.yaml index dff39a0f1..8772d3f86 100644 --- a/roles/ensure-tox/tasks/main.yaml +++ b/roles/ensure-tox/tasks/main.yaml @@ -21,11 +21,11 @@ - name: Install tox to local env when: tox_preinstalled.rc != 0 block: + - name: Create local venv + command: '{{ ensure_pip_virtualenv_command }} {{ tox_venv_path }}' + - name: Install tox to local venv - pip: - name: tox - virtualenv_command: '{{ ensure_pip_virtualenv_command }}' - virtualenv: '{{ tox_venv_path }}' + command: '{{ tox_venv_path }}/bin/pip install tox' - name: Export installed tox_executable path set_fact: @@ -34,3 +34,13 @@ - name: Output tox version command: "{{ tox_executable }} --version" + +- name: Make global symlink + when: + - ensure_global_symlinks + - tox_executable != '/usr/local/bin/tox' + file: + state: link + src: "{{ tox_executable }}" + dest: /usr/local/bin/tox + become: yes diff --git a/test-playbooks/ensure-tox.yaml b/test-playbooks/ensure-tox.yaml index e2da047c5..d245112c3 100644 --- a/test-playbooks/ensure-tox.yaml +++ b/test-playbooks/ensure-tox.yaml @@ -40,11 +40,10 @@ - hosts: all name: Test ensure-tox when tox_executable is set to an already installed tox tasks: - - name: Install tox inside a virtualenv - pip: - name: tox - virtualenv: "{{ ansible_user_dir }}/tox-venv" - virtualenv_command: "{{ ensure_pip_virtualenv_command }}" + - name: Create a virtualenv + command: '{{ ensure_pip_virtualenv_command }} {{ ansible_user_dir }}/tox-venv' + - name: Install tox to local venv + command: '{{ ansible_user_dir }}/tox-venv/bin/pip install tox' - name: Run ensure-tox pointing to an already installed tox include_role: name: ensure-tox