diff --git a/defaults/main.yml b/defaults/main.yml index ae64a26..c205040 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -37,8 +37,19 @@ watcher_git_install_branch: master watcher_developer_constraints: - "git+{{ watcher_git_repo }}@{{ watcher_git_install_branch }}#egg=watcher" +# TODO(odyssey4me): +# This can be simplified once all the roles are using +# python_venv_build. We can then switch to using a +# set of constraints in pip.conf inside the venv, +# perhaps prepared by giving a giving a list of +# constraints to the role. +watcher_pip_install_args: >- + {{ watcher_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }} + {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''), '') }} + {{ pip_install_options | default('') }} + # Name of the virtual env to deploy into -watcher_venv_tag: untagged +watcher_venv_tag: "{{ venv_tag | default('untagged') }}" watcher_bin: "/openstack/venvs/watcher-{{ watcher_venv_tag }}/bin" # venv_download, even when true, will use the fallback method of building the diff --git a/handlers/main.yml b/handlers/main.yml index 6909300..a6da7fe 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -38,3 +38,5 @@ pattern: "{{ item }}" with_items: "{{ watcher_service_names }}" failed_when: false + listen: + - "venv changed" diff --git a/tasks/install-apt.yml b/tasks/install-apt.yml deleted file mode 100644 index 363e2dc..0000000 --- a/tasks/install-apt.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -# Copyright 2016, Walmart Stores, 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 apt packages - apt: - pkg: "{{ item }}" - state: "{{ watcher_package_state }}" - update_cache: yes - cache_valid_time: "{{ cache_timeout }}" - register: install_packages - until: install_packages is success - retries: 5 - delay: 2 - with_items: "{{ watcher_distro_packages }}" - -- name: Install packages required in Developer Mode - apt: - pkg: "{{ item }}" - state: "{{ watcher_package_state }}" - register: install_packages - until: install_packages is success - retries: 5 - delay: 2 - with_items: "{{ watcher_developer_mode_distro_packages }}" - when: - - watcher_developer_mode | bool diff --git a/tasks/watcher_install.yml b/tasks/watcher_install.yml index 8601357..14da931 100644 --- a/tasks/watcher_install.yml +++ b/tasks/watcher_install.yml @@ -13,10 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -- include_tasks: install-apt.yml - static: no - when: ansible_pkg_mgr == 'apt' - +# TODO(odyssey4me): +# This can be simplified once all the roles are using +# python_venv_build. We can then switch to using a +# set of constraints in pip.conf inside the venv, +# perhaps prepared by giving a giving a list of +# constraints to the role. - name: Create developer mode constraint file copy: dest: "/opt/developer-pip-constraints.txt" @@ -27,90 +29,22 @@ when: - watcher_developer_mode | bool -- name: Retrieve checksum for venv download - uri: - url: "{{ watcher_venv_download_url | replace('tgz', 'checksum') }}" - return_content: yes - register: watcher_venv_checksum - when: watcher_venv_download | bool +- name: Ensure remote wheel building is disabled in developer mode + set_fact: + venv_build_host: "{{ ansible_hostname }}" + when: + - watcher_developer_mode | bool -- name: Attempt venv download - get_url: - url: "{{ watcher_venv_download_url }}" - dest: "/var/cache/{{ watcher_venv_download_url | basename }}" - checksum: "sha1:{{ watcher_venv_checksum.content | trim }}" - register: watcher_get_venv - when: watcher_venv_download | bool - -- name: Remove existing venv - file: - path: "{{ watcher_bin | dirname }}" - state: absent - when: watcher_get_venv is changed - -- name: Create watcher venv dir - file: - path: "{{ watcher_bin | dirname }}" - state: directory - register: watcher_venv_dir - when: watcher_get_venv is changed - -- name: Unarchive pre-built venv - unarchive: - src: "/var/cache/{{ watcher_venv_download_url | basename }}" - dest: "{{ watcher_bin | dirname }}" - copy: "no" - when: watcher_get_venv is changed - notify: Restart watcher services - -- name: Install pip packages - pip: - name: "{{ watcher_pip_packages }}" - state: "{{ watcher_pip_package_state }}" - virtualenv: "{{ watcher_bin | dirname }}" - virtualenv_site_packages: "no" - extra_args: >- - {{ watcher_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }} - {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }} - {{ pip_install_options | default('') }} - register: install_packages - until: install_packages is success - retries: 5 - delay: 2 - when: watcher_get_venv | failed or watcher_get_venv | skipped - notify: Restart watcher services - -- name: Install optional pip packages - pip: - name: "{{ watcher_optional_oslomsg_amqp1_pip_packages }}" - state: "{{ watcher_pip_package_state }}" - virtualenv: "{{ watcher_bin | dirname }}" - virtualenv_site_packages: "no" - when: watcher_oslomsg_amqp1_enabled - register: install_optional_packages - until: install_optional_packages is success - retries: 5 - delay: 2 - notify: - - Manage LB - - Restart watcher services - -# 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 path - shell: | - find {{ watcher_bin }} -name \*.pyc -delete - sed -si '1s/^.*python.*$/#!{{ watcher_bin | replace ('/','\/') }}\/python/' {{ watcher_bin }}/* - virtualenv {{ watcher_bin | dirname }} \ - {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \ - --no-pip \ - --no-setuptools \ - --no-wheel - when: watcher_get_venv is changed - tags: - - skip_ansible_lint +- name: Install the python venv + include_role: + name: "python_venv_build" + private: yes + vars: + venv_install_destination_path: "{{ watcher_bin | dirname }}" + venv_install_distro_package_list: "{{ watcher_distro_packages }}" + venv_pip_install_args: "{{ watcher_pip_install_args }}" + venv_pip_packages: "{{ (watcher_oslomsg_amqp1_enabled | bool) | ternary(watcher_pip_packages + watcher_optional_oslomsg_amqp1_pip_packages, watcher_pip_packages) }}" + venv_facts_when_changed: + - section: "watcher" + option: "venv_tag" + value: "{{ watcher_venv_tag }}"