Ensure distribution/architecture separation

Sometimes venvs are not very reusable across distributions
and architectures, so to ensure this doesn't happen we
store them in entirely different paths.
This commit is contained in:
Jesse Pretorius 2018-03-23 12:26:27 +00:00
parent c3e210e9e7
commit 7a01d139ff
4 changed files with 24 additions and 15 deletions

View File

@ -61,8 +61,15 @@ venv_pip_install_args: ""
venv_reuse_enable: yes
# The path where a built venv should be stored on the
# deployment host.
venv_reuse_download_path: "{{ lookup('env', 'HOME') | default('/opt', true) }}/cache"
# deployment host. By default, ensure that the location
# separates venvs per distribution and architecture to
# prevent re-use of venvs between them.
venv_reuse_download_path: "{{ lookup('env', 'HOME') | default('/opt', true) }}/cache/{{ venv_reuse_download_subfolder }}"
# NOTE(hwoarang): ansible_distribution may return a string with spaces
# such as "openSUSE Leap" so we need to replace the space with underscore
# in order to create a more sensible repo name for the distro.
venv_reuse_download_subfolder: "{{ (ansible_distribution | lower) | replace(' ', '_') }}-{{ ansible_distribution_version.split('.')[:2] | join('.') }}-{{ ansible_architecture | lower }}"
# The owner of the venv_reuse_download_path
venv_reuse_download_path_owner: "{{ lookup('env', 'USER') | default('root', true) }}"

View File

@ -105,9 +105,9 @@
flat: yes
with_items:
- src: "{{ venv_destination_path }}.tgz"
dest: "{{ venv_reuse_download_path }}/{{ 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 }}.checksum"
dest: "{{ venv_reuse_download_path }}/{{ venv_destination_path | basename }}.checksum"
when:
- _venv_package_build is mapping
- _venv_package_build | changed

View File

@ -15,7 +15,7 @@
- name: Copy the venv checksum file to the target host
copy:
src: "{{ venv_reuse_download_path }}/{{ venv_destination_path }}.checksum"
src: "{{ venv_reuse_download_path }}/{{ venv_destination_path | basename }}.checksum"
dest: "{{ venv_destination_path | dirname }}"
register: _venv_checksum_copy
- _src_venv_present.stat.exists | bool
@ -34,7 +34,7 @@
- name: Unarchive pre-built venv
unarchive:
src: "{{ venv_reuse_download_path }}/{{ venv_destination_path }}.tgz"
src: "{{ venv_reuse_download_path }}/{{ venv_destination_path | basename }}.tgz"
dest: "{{ venv_destination_path }}"
remote_src: no
- _venv_checksum_copy is mapping

View File

@ -21,9 +21,19 @@
when:
- venv_destination_path is not defined
- name: Ensure that venv_reuse_download_path exists on the deployment host
file:
path: "{{ venv_reuse_download_path }}"
state: directory
owner: "{{ venv_reuse_download_path_owner }}"
delegate_to: localhost
run_once: yes
when:
- venv_reuse_enable | bool
- name: Check if venv tgz is present on the deployment host
stat:
path: "{{ venv_reuse_download_path }}/{{ venv_destination_path }}.tgz"
path: "{{ venv_reuse_download_path }}/{{ venv_destination_path | basename }}.tgz"
get_attributes: no
get_checksum: no
get_md5: no
@ -31,13 +41,5 @@
register: _src_venv_present
delegate_to: localhost
run_once: yes
- name: Ensure that venv_reuse_download_path exists on the deployment host
file:
path: "{{ venv_reuse_download_path }}/{{ venv_destination_path | dirname }}"
state: directory
owner: "{{ venv_reuse_download_path_owner }}"
delegate_to: localhost
run_once: yes
when:
- venv_reuse_enable | bool