ansible-role-python_venv_build/tasks/python_venv_install.yml
Jesse Pretorius c54aa8117e Add default distro packages for wheel builds
There are some packages which absolutely must be there
for all wheel builds, or for installing without wheels.
Without them, pip is totally unable to compile the
package due to missing headers or tooling.

This patch adds a default, minimal, set of compilers
and python headers.

Rather than use include_vars, with_first_found as we
do in most other roles, we use vars/main and a dict
based on ansible_os_family. The role is often included
by other roles, and we'd rather not risk the search
path being incorrect (there are constant bugs related
to this in ansible). Using this mechanism takes away
the need for an include_vars task and avoids any pathing
issues.

Change-Id: I4ef11e47e4d3fe5adc65e9888e660a5a121d205b
2018-10-31 10:35:20 +00:00

86 lines
3.0 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.
# TODO(odyssey4me):
# Set a fact for the selective inclusion of the build package list.
# Perhaps do this if the distro/architecture of the target host differs
# from the build host.
- name: Install distro packages for venv build
package:
name: "{{ (venv_build_host != inventory_hostname) | ternary(venv_install_distro_package_list, (venv_build_base_distro_package_list + venv_build_distro_package_list + venv_install_distro_package_list) | unique) }}"
state: "{{ venv_distro_package_state }}"
update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}"
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(venv_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 is success
retries: 5
delay: 2
- name: Ensure a fresh venv_install_destination_path if venv_rebuild is enabled
file:
path: "{{ venv_install_destination_path }}"
state: absent
when:
- venv_rebuild | bool
# NOTE(odyssey4me):
# Not using --always-copy for CentOS/SuSE due to
# https://github.com/pypa/virtualenv/issues/565
- name: Create the virtualenv (if it does not exist)
command: >-
virtualenv
{{ _venv_create_extra_options }}
--python={{ venv_python_executable }}
{{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }}
{{ venv_install_destination_path }}
args:
creates: "{{ venv_install_destination_path }}/bin/activate"
- name: Upgrade pip/setuptools/wheel to the versions we want
pip:
name:
- pip
- setuptools
- wheel
state: "{{ venv_pip_package_state }}"
virtualenv: "{{ venv_install_destination_path }}"
extra_args: >-
--log /var/log/python_venv_build.log
{{ venv_pip_install_args }}
register: _update_virtualenv_packages
until: _update_virtualenv_packages is success
retries: 5
delay: 2
- name: Install python packages into the venv
pip:
name: "{{ venv_default_pip_packages + venv_pip_packages }}"
state: "{{ venv_pip_package_state }}"
virtualenv: "{{ venv_install_destination_path }}"
extra_args: >-
--pre
--log /var/log/python_venv_build.log
{{ venv_pip_install_args }}
register: _install_venv_pip_packages
until: _install_venv_pip_packages is success
retries: 5
delay: 2
notify:
- venv changed