
Some python packages have C bindings which tend to be very particular about the version of their underlying shared libraries. To ensure things run smoothly for stable releases, we opt to use the distro packages for these python packages and symlink the appropriate python library files and their bindings into the venv. This functionality is required for libvirt and ceph and is used across multiple roles. Change-Id: Ib5b7fa1d06abe1e1bb4f14aea7de4207b61aca88
121 lines
4.2 KiB
YAML
121 lines
4.2 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
|
|
|
|
- name: Add symlinks from distribution python packages
|
|
when:
|
|
- venv_packages_to_symlink | length > 0
|
|
block:
|
|
- name: Find the venv's python version
|
|
find:
|
|
paths: "{{ venv_install_destination_path }}/lib/"
|
|
patterns: "python*"
|
|
file_type: directory
|
|
recurse: no
|
|
register: _python_venv_details
|
|
|
|
- name: Set python venv details
|
|
set_fact:
|
|
venv_python_version: "{{ (_python_venv_details.files[0].path | basename) }}"
|
|
venv_python_major_version: "{{ (_python_venv_details.files[0].path | basename)[:-2] }}"
|
|
venv_python_lib_folder: "{{ _python_venv_details.files[0].path }}"
|
|
|
|
- name: Search for lib files to link
|
|
shell: >-
|
|
{{ (ansible_pkg_mgr == 'apt') | ternary('dpkg -L ' ~ (venv_packages_to_symlink | join(' ')), 'rpm -ql ' ~ (venv_packages_to_symlink | join(' ')) ) }}
|
|
| egrep '^.*{{ venv_python_major_version }}.*/(site|dist)-packages/.*'
|
|
args:
|
|
warn: no
|
|
changed_when: false
|
|
register: _python_files
|
|
|
|
- name: Link the python host package files into venv
|
|
file:
|
|
src: "{{ item }}"
|
|
dest: "{{ venv_python_lib_folder }}/site-packages/{{ item | basename }}"
|
|
state: link
|
|
force: yes
|
|
with_items: "{{ _python_files.stdout_lines }}"
|