Add ability to symlink host python packages into venv
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
This commit is contained in:
parent
c54aa8117e
commit
5a31e77fb4
|
@ -59,6 +59,15 @@ venv_pip_packages: []
|
|||
# Arguments to pass to pip when installing into the venv
|
||||
venv_pip_install_args: ""
|
||||
|
||||
# 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 variable should contain the list of packages installed which
|
||||
# should be symlinked into the venv.
|
||||
venv_packages_to_symlink: []
|
||||
|
||||
# The python executable to use for creating the venv
|
||||
venv_python_executable: "python2"
|
||||
|
||||
|
|
|
@ -83,3 +83,38 @@
|
|||
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 }}"
|
||||
|
|
Loading…
Reference in New Issue