From 787634eeb5d7e4fa15dfb1e7a1c7c938e856b979 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Sat, 14 May 2016 09:46:48 -0500 Subject: [PATCH] Updated the installation tasks to support remote venvs The changes bring the role inline with others to make it possible to download a pre-built venv. Signed-off-by: Kevin Carter --- defaults/main.yml | 29 +++-- tasks/cloudkitty_install.yml | 196 ++++++++++++++++++++++++++++--- tasks/cloudkitty_pre_install.yml | 20 +--- 3 files changed, 196 insertions(+), 49 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 5c67376..a0159a7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -24,13 +24,25 @@ cloudkitty_system_comment: meow cloudkitty_system_shell: /bin/false cloudkitty_venv_tag: untagged -cloudkitty_venv_dir: "/openstack/venvs/cloudkitty-{{ cloudkitty_venv_tag }}" +cloudkitty_venv_bin: "/openstack/venvs/cloudkitty-{{ cloudkitty_venv_tag }}/bin" + +# Set this to enable or disable installing in a venv +cloudkitty_venv_enabled: true + +# The bin path defaults to the venv path however if installation in a +# venv is disabled the bin path will be dynamically set based on the +# system path used when the installing. +cloudkitty_bin: "{{ cloudkitty_venv_bin }}" + +cloudkitty_venv_download_url: http://127.0.0.1/venvs/untagged/ubuntu/cloudkitty.tgz cloudkitty_git_repo: https://github.com/openstack/cloudkitty.git cloudkitty_git_install_branch: master cloudkitty_requirements_git_repo: https://git.openstack.org/openstack/requirements cloudkitty_requirements_git_install_branch: master +cloudkitty_developer_constraints: + - "git+{{ cloudkitty_git_repo }}@{{ cloudkitty_requirements_git_install_branch }}#egg=cloudkitty" cloudkitty_developer_mode: false cloudkitty_notification_topics: openstack @@ -67,7 +79,6 @@ cloudkitty_service_internaluri: "{{ cloudkitty_service_internaluri_proto }}://{{ cloudkitty_service_internalurl: "{{ cloudkitty_service_internaluri }}/v1/%(tenant_id)s" cloudkitty_service_program_name: cloudkitty-api - cloudkitty_cloudkitty_conf_overrides: {} cloudkitty_policy_overrides: {} cloudkitty_api_paste_ini_overrides: {} @@ -91,20 +102,12 @@ cloudkitty_pip_packages: - python-swiftclient - python-troveclient -# Name of the virtual env to deploy into -cloudkitty_venv_bin: "{{ cloudkitty_venv_dir }}/bin" - -# Set this to enable or disable installing in a venv -cloudkitty_venv_enabled: true - -# The bin path defaults to the venv path however if installation in a -# venv is disabled the bin path will be dynamically set based on the -# system path used when the installing. -cloudkitty_bin: "{{ cloudkitty_venv_bin }}" - cloudkitty_requires_pip_packages: - virtualenv + - virtualenv-tools - python-keystoneclient + - httplib2 + # The messaging driver to use, defaults to rabbit. Other drivers # include qpid and zmq. (string value) cloudkitty_rpc_backend: rabbit diff --git a/tasks/cloudkitty_install.yml b/tasks/cloudkitty_install.yml index d49a225..d53d419 100644 --- a/tasks/cloudkitty_install.yml +++ b/tasks/cloudkitty_install.yml @@ -15,40 +15,202 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Install cloudkitty packages (venv) +- name: Create developer mode constraint file + copy: + dest: "/opt/developer-pip-constraints.txt" + content: | + {% for item in cloudkitty_developer_constraints %} + {{ item }} + {% endfor %} + when: + - cloudkitty_developer_mode | bool + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Clone requirements git repository + git: + repo: "{{ cloudkitty_requirements_git_repo }}" + dest: "/opt/requirements" + clone: yes + update: yes + version: "{{ cloudkitty_requirements_git_install_branch }}" + when: + - cloudkitty_developer_mode | bool + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Add constraints to pip_install_options fact for developer mode + set_fact: + pip_install_options_fact: "{{ pip_install_options|default('') }} --constraint /opt/developer-pip-constraints.txt --constraint /opt/requirements/upper-constraints.txt" + when: + - cloudkitty_developer_mode | bool + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Set pip_install_options_fact when not in developer mode + set_fact: + pip_install_options_fact: "{{ pip_install_options|default('') }}" + when: + - not cloudkitty_developer_mode | bool + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Install requires pip packages pip: name: "{{ item }}" - state: present - virtualenv: "{{ cloudkitty_venv_dir }}" - virtualenv_site_packages: "no" + state: latest + extra_args: "{{ pip_install_options_fact }}" register: install_packages until: install_packages|success retries: 5 delay: 2 - with_items: - - "{{ cloudkitty_pip_packages }}" + with_items: cloudkitty_requires_pip_packages + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Get local venv checksum + stat: + path: "/var/cache/{{ cloudkitty_venv_download_url | basename }}" + get_md5: False + when: + - not cloudkitty_developer_mode | bool + - cloudkitty_venv_enabled | bool + register: local_venv_stat + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Get remote venv checksum + uri: + url: "{{ cloudkitty_venv_download_url | replace('tgz', 'checksum') }}" + return_content: True + when: + - not cloudkitty_developer_mode | bool + - cloudkitty_venv_enabled | bool + register: remote_venv_checksum + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +# TODO: When project moves to ansible 2 we can pass this a sha256sum which will: +# a) allow us to remove force: yes +# b) allow the module to calculate the checksum of dest file which would +# result in file being downloaded only if provided and dest sha256sum +# checksums differ +- name: Attempt venv download + get_url: + url: "{{ cloudkitty_venv_download_url }}" + dest: "/var/cache/{{ cloudkitty_venv_download_url | basename }}" + force: yes + ignore_errors: true + register: get_venv + when: + - not cloudkitty_developer_mode | bool + - cloudkitty_venv_enabled | bool + - (local_venv_stat.stat.exists == False or + {{ local_venv_stat.stat.checksum is defined and local_venv_stat.stat.checksum != remote_venv_checksum.content | trim }}) + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Set cloudkitty get_venv fact + set_fact: + cloudkitty_get_venv: "{{ get_venv }}" + when: cloudkitty_venv_enabled | bool + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Remove existing venv + file: + path: "{{ cloudkitty_venv_bin | dirname }}" + state: absent when: - cloudkitty_venv_enabled | bool -# notify: -# - Restart cloudkitty api + - cloudkitty_get_venv | changed tags: - cloudkitty-install - - cloudkitty-install-pip-packages + - cloudkitty-pip-packages -- name: Install cloudkitty pip packages (no venv) +- name: Create cloudkitty venv dir + file: + path: "{{ cloudkitty_venv_bin | dirname }}" + state: directory + when: + - not cloudkitty_developer_mode | bool + - cloudkitty_venv_enabled | bool + - cloudkitty_get_venv | changed + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Unarchive pre-built venv + unarchive: + src: "/var/cache/{{ cloudkitty_venv_download_url | basename }}" + dest: "{{ cloudkitty_venv_bin | dirname }}" + copy: "no" + when: + - not cloudkitty_developer_mode | bool + - cloudkitty_venv_enabled | bool + - cloudkitty_get_venv | changed + # notify: + # - Restart cloudkitty api + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Update virtualenv path + command: > + virtualenv-tools --update-path=auto {{ cloudkitty_venv_bin | dirname }} + when: + - not cloudkitty_developer_mode | bool + - cloudkitty_venv_enabled | bool + - cloudkitty_get_venv | success + tags: + - cloudkitty-install + - cloudkitty-pip-packages + +- name: Install pip packages (venv) pip: name: "{{ item }}" - state: present + state: latest + virtualenv: "{{ cloudkitty_venv_bin | dirname }}" + virtualenv_site_packages: "no" + extra_args: "{{ pip_install_options_fact }}" register: install_packages until: install_packages|success retries: 5 delay: 2 - with_items: - - "{{ cloudkitty_pip_packages }}" + with_items: cloudkitty_pip_packages when: - - not cloudkitty_venv_enabled | bool -# notify: -# - Restart cloudkitty api + - cloudkitty_venv_enabled | bool + - cloudkitty_get_venv | failed or cloudkitty_developer_mode | bool + # notify: + # - Restart cloudkitty api tags: - cloudkitty-install - - cloudkitty-install-pip-packages + - cloudkitty-pip-packages + +- name: Install pip packages (no venv) + pip: + name: "{{ item }}" + state: latest + extra_args: "{{ pip_install_options_fact }}" + register: install_packages + until: install_packages|success + retries: 5 + delay: 2 + with_items: cloudkitty_pip_packages + when: + - not cloudkitty_developer_mode | bool + - not cloudkitty_venv_enabled | bool + # notify: + # - Restart cloudkitty api + tags: + - cloudkitty-install + - cloudkitty-pip-packages diff --git a/tasks/cloudkitty_pre_install.yml b/tasks/cloudkitty_pre_install.yml index e0ebfa0..e6b0ccd 100644 --- a/tasks/cloudkitty_pre_install.yml +++ b/tasks/cloudkitty_pre_install.yml @@ -54,7 +54,7 @@ state: directory with_items: - { path: "/openstack/venvs" } - - { path: "{{ cloudkitty_venv_bin }}" } + - { path: "{{ cloudkitty_venv_bin | dirname }}" } when: cloudkitty_venv_enabled | bool tags: - cloudkitty-dirs @@ -88,24 +88,6 @@ - cloudkitty-dirs - cloudkitty-logs -- name: Pip required packages for CloudKitty - pip: - name: "{{ item }}" - state: present - register: install_packages - until: install_packages|success - retries: 5 - delay: 2 - with_items: - - "{{ cloudkitty_requires_pip_packages }}" - when: - - cloudkitty_venv_enabled | bool - notify: -# - Restart cloudkitty api - tags: - - cloudkitty-usage-install - - cloudkitty-usage-install-pip-packages - - name: Create cloudkitty report dir file: path: "{{ cloudkitty_output_basepath }}"