114 lines
3.7 KiB
YAML
114 lines
3.7 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: "{{ distro_package_list }}"
|
|
state: "{{ 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: distro_package_list | length > 0
|
|
register: _install_distro_packages
|
|
until: _install_distro_packages | success
|
|
retries: 5
|
|
delay: 2
|
|
|
|
- name: Install pip packages on the host for venv build
|
|
pip:
|
|
name: "{{ host_pip_packages }}"
|
|
state: "{{ pip_package_state }}"
|
|
extra_args: "{{ host_pip_install_args }}"
|
|
when: host_pip_packages | length > 0
|
|
register: _install_host_pip_packages
|
|
until: _install_host_pip_packages | success
|
|
retries: 5
|
|
delay: 2
|
|
|
|
- name: Create venv directory on the target host
|
|
file:
|
|
path: "{{ venv_destination_path }}"
|
|
state: directory
|
|
|
|
#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: "{{ pip_package_state }}"
|
|
virtualenv: "{{ venv_destination_path }}"
|
|
virtualenv_site_packages: "no"
|
|
extra_args: "{{ 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_reuse_enable is enabled
|
|
when: venv_reuse_enable | bool
|
|
block:
|
|
|
|
- name: Clean up the virtualenv before packaging
|
|
shell: |
|
|
find {{ venv_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_destination_path }}.tgz' -C '{{ venv_destination_path }}' .
|
|
args:
|
|
chdir: "{{ venv_destination_path }}"
|
|
executable: /bin/bash
|
|
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_destination_path }}.tgz' | awk '{print $1}' > '{{ venv_destination_path }}.checksum'
|
|
args:
|
|
executable: /bin/bash
|
|
when:
|
|
- _venv_package_build is mapping
|
|
- _venv_package_build | changed
|
|
|
|
- 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_destination_path }}.tgz"
|
|
dest: "{{ venv_reuse_download_path }}/{{ venv_destination_path | basename }}.tgz"
|
|
- src: "{{ venv_destination_path }}.checksum"
|
|
dest: "{{ venv_reuse_download_path }}/{{ venv_destination_path | basename }}.checksum"
|
|
when:
|
|
- _venv_package_build is mapping
|
|
- _venv_package_build | changed
|