
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
145 lines
5.1 KiB
YAML
145 lines
5.1 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: Install distro packages for venv build
|
|
package:
|
|
name: "{{ venv_build_distro_package_list + venv_install_distro_package_list }}"
|
|
state: "{{ venv_distro_package_state }}"
|
|
update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}"
|
|
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(distro_cache_valid_time, omit) }}"
|
|
when:
|
|
- (venv_build_distro_package_list | length > 0) or
|
|
(venv_install_distro_package_list | length > 0)
|
|
register: _install_distro_packages
|
|
until: _install_distro_packages | success
|
|
retries: 5
|
|
delay: 2
|
|
|
|
- name: Ensure a fresh venv_install_destination_path if venv_build_only is enabled
|
|
file:
|
|
path: "{{ venv_install_destination_path }}"
|
|
state: absent
|
|
when:
|
|
- venv_build_only | bool
|
|
|
|
- name: Create wheel/venv directories on the target host
|
|
file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
with_items:
|
|
- "{{ venv_build_archive_path }}"
|
|
- "{{ venv_build_wheel_path }}"
|
|
- "{{ venv_install_destination_path }}"
|
|
|
|
- name: Build wheels for the packages to be installed into the venv
|
|
command: >-
|
|
pip wheel
|
|
--wheel-dir {{ venv_build_wheel_path }}/
|
|
--find-links {{ venv_build_wheel_path }}/
|
|
--log /var/log/python_wheel_build.log
|
|
{{ venv_pip_install_args }}
|
|
{{ venv_pip_packages | join(' ') }}
|
|
when:
|
|
- venv_build_wheels | bool
|
|
|
|
#TODO(odyssey4me):
|
|
# Split the venv build into multiple parts:
|
|
# 1. Create the venv without pip, setuptools, wheel
|
|
# 2. Use get-pip.py to install the right versions
|
|
# of pip, setuptools, wheel into the venv
|
|
# 3. Install the packages into the venv
|
|
|
|
- name: Build venv
|
|
pip:
|
|
name: "{{ venv_pip_packages }}"
|
|
state: "{{ venv_pip_package_state }}"
|
|
virtualenv: "{{ venv_install_destination_path }}"
|
|
virtualenv_site_packages: "no"
|
|
virtualenv_python: "{{ venv_python_executable }}"
|
|
extra_args: >-
|
|
--find-links {{ venv_build_wheel_path }}/
|
|
--log /var/log/python_venv_build.log
|
|
{{ venv_pip_install_args }}
|
|
register: _install_venv_pip_packages
|
|
until: _install_venv_pip_packages | success
|
|
retries: 5
|
|
delay: 2
|
|
notify:
|
|
- venv changed
|
|
|
|
- name: Package the venv when venv_build_package is enabled
|
|
when:
|
|
- venv_build_package | bool
|
|
block:
|
|
|
|
- name: Clean up the virtualenv before packaging
|
|
shell: |
|
|
find {{ venv_install_destination_path }}/bin -type f -name '*.pyc' -delete
|
|
when:
|
|
- _install_venv_pip_packages is mapping
|
|
- _install_venv_pip_packages | changed
|
|
|
|
# Note(odyssey4me):
|
|
# We purposefully use shell instead of the archive module
|
|
# here. The archive module's output is far too verbose to
|
|
# be practical when debugging.
|
|
- name: Package venv
|
|
command: |
|
|
tar czf '{{ venv_build_archive_path }}/{{ venv_install_destination_path | basename }}.tgz' -C '{{ venv_install_destination_path }}' .
|
|
args:
|
|
chdir: "{{ venv_install_destination_path }}"
|
|
warn: no
|
|
register: _venv_package_build
|
|
when:
|
|
- _install_venv_pip_packages is mapping
|
|
- _install_venv_pip_packages | changed
|
|
|
|
- name: Prepare checksum for packaged venv
|
|
shell: |
|
|
sha1sum '{{ venv_build_archive_path }}/{{ venv_install_destination_path | basename }}.tgz' | awk '{print $1}' > '{{ venv_build_archive_path }}/{{ venv_install_destination_path | basename }}.checksum'
|
|
args:
|
|
executable: /bin/bash
|
|
when:
|
|
- _venv_package_build is mapping
|
|
- _venv_package_build | changed
|
|
|
|
- name: Ensure that venv_install_source_path exists on the deployment host
|
|
file:
|
|
path: "{{ venv_install_source_path }}"
|
|
state: directory
|
|
owner: "{{ lookup('env', 'USER') }}"
|
|
recurse: yes
|
|
delegate_to: localhost
|
|
run_once: yes
|
|
when:
|
|
- _venv_source == 'file'
|
|
- inventory_hostname != 'localhost'
|
|
|
|
- name: Copy the packaged venv and checksum file to the deployment host
|
|
fetch:
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
flat: yes
|
|
with_items:
|
|
- src: "{{ venv_build_archive_path }}/{{ venv_install_destination_path | basename }}.tgz"
|
|
dest: "{{ venv_install_source_path }}/{{ venv_install_destination_path | basename }}.tgz"
|
|
- src: "{{ venv_build_archive_path }}/{{ venv_install_destination_path | basename }}.checksum"
|
|
dest: "{{ venv_install_source_path }}/{{ venv_install_destination_path | basename }}.checksum"
|
|
when:
|
|
- _venv_source == 'file'
|
|
- _venv_package_build is mapping
|
|
- _venv_package_build | changed
|
|
- inventory_hostname != 'localhost'
|