ansible-role-python_venv_build/tasks/python_venv_preflight.yml
Jesse Pretorius d169906c68 Revise the role to properly cater to use-cases
1. Variables have been renamed to make it easier to
   understand their purpose.
2. Unnecessary variables have been removed.
3. The role no longer caters to installing pip packages
   on the host. This should never be necessary - if it
   is, then something should do so beforehand.
4. The expected versions of pip/virtualenv are documented
   and a check has been added to ensure that they exist.
5. The handler has been named to make debug logs less
   confusing.
6. The default storage path for venvs/wheels is no longer
   opinionated. If paths based on distro/architecture are
   required then different paths should be provided to
   the role.

Change-Id: I9eb96e9db22f918b00456af943d81f66050107ce
2018-05-04 18:03:59 +01:00

78 lines
2.5 KiB
YAML

---
# Copyright 2018, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Verify that venv_install_destination_path has been provided
fail:
msg: |
The variable venv_install_destination_path is required and
has not been set.
when:
- venv_install_destination_path is not defined
- name: Collect the version of virtualenv
shell: |
virtualenv --version 2>/dev/null || echo 'none'
args:
executable: /bin/bash
changed_when: false
failed_when: false
register: _virtualenv_version
- name: Collect the version of pip
shell: |
pip --version 2>/dev/null | awk '{print $2}' || echo 'none'
args:
executable: /bin/bash
changed_when: false
failed_when: false
register: _pip_version
- name: Fail when required virtualenv version is not present
fail:
msg: >-
The required virtualenv version is not present.
The minimum version of 13.0.0 is required, but
{{ _virtualenv_version.stdout }} is installed.
when:
- ((_virtualenv_version.stdout | trim) == 'none') or
((_virtualenv_version.stdout | trim) is version_compare('13.0.0', '<'))
- name: Fail when required pip version is not present
fail:
msg: >-
The required virtualenv version is not present.
The minimum version of 7.1 is required, but
{{ _pip_version.stdout }} is installed.
when:
- ((_pip_version.stdout | trim) == 'none') or
((_pip_version.stdout | trim) is version_compare('7.1', '<'))
- name: Check whether the venv_install_source_path is a URL or a file path
set_fact:
_venv_source: "{{ ((venv_install_source_path | trim) is match('^https?://.*')) | ternary('url', 'file') }}"
- name: Check if venv tgz is present on the deployment host
stat:
path: "{{ venv_install_source_path }}/{{ venv_install_destination_path | basename }}.tgz"
get_attributes: no
get_checksum: no
get_md5: no
get_mime: no
register: _src_venv_present
delegate_to: localhost
run_once: yes
when:
- _venv_source == 'file'