--- # 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 install package: name: "{{ venv_install_distro_package_list }}" state: "{{ venv_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: - venv_install_distro_package_list | length > 0 register: _install_distro_packages until: _install_distro_packages is success retries: 5 delay: 2 - name: Create venv parent directories on the target host file: path: "{{ venv_install_destination_path | dirname }}" state: directory - name: Copy the venv archive checksum copy: src: "{{ venv_install_source_path }}/{{ venv_install_destination_path | basename }}.checksum" dest: "{{ venv_install_destination_path | dirname }}/" register: _venv_checksum_copy when: - _venv_source == 'file' - name: Copy the venv archive copy: src: "{{ venv_install_source_path }}/{{ venv_install_destination_path | basename }}.tgz" dest: "{{ venv_install_destination_path | dirname }}/" when: - _venv_source == 'file' - name: Download the venv archive checksum uri: url: "{{ venv_install_source_path }}/{{ venv_install_destination_path | basename }}.checksum" dest: "{{ venv_install_destination_path | dirname }}/" return_content: yes register: _venv_checksum_download when: - _venv_source == 'url' - name: Download the venv archive get_url: url: "{{ venv_install_source_path }}/{{ venv_install_destination_path | basename }}.tgz" dest: "{{ venv_install_destination_path | dirname }}/" checksum: "sha1:{{ _venv_checksum_download.content | trim }}" when: - _venv_source == 'url' - name: Remove existing venv on target host if it is changing file: path: "{{ venv_install_destination_path }}" state: absent when: - (_venv_checksum_copy is mapping and _venv_checksum_copy | changed) or (_venv_checksum_download is mapping and _venv_checksum_download | changed) - name: Create venv directory on the target host file: path: "{{ venv_install_destination_path }}" state: directory register: _venv_dir_create - name: Unarchive pre-built venv unarchive: src: "{{ venv_install_destination_path }}.tgz" dest: "{{ venv_install_destination_path }}" remote_src: yes when: - (_venv_checksum_copy is mapping and _venv_checksum_copy | changed) or (_venv_checksum_download is mapping and _venv_checksum_download | changed) or _venv_dir_create is changed notify: - venv changed # NOTE(odyssey4me): # We reinitialize the venv to ensure that the right # version of python is in the venv, but we do not # want virtualenv to also replace pip, setuptools # and wheel so we tell it not to. # We do not use --always-copy for CentOS/SuSE due # to https://github.com/pypa/virtualenv/issues/565 - name: Update virtualenv python and paths shell: | sed -si '1s/^.*python.*$/#!{{ (venv_install_destination_path ~ '/bin') | replace ('/','\/') }}\/python/' {{ venv_install_destination_path }}/bin/* virtualenv {{ venv_install_destination_path }} \ {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \ --no-pip \ --no-setuptools \ --no-wheel args: executable: /bin/bash warn: no when: - (_venv_checksum_copy is mapping and _venv_checksum_copy | changed) or (_venv_checksum_download is mapping and _venv_checksum_download | changed) or _venv_dir_create is changed tags: - skip_ansible_lint