/etc/ansible/roles/os_murano/tasks/murano_import_libraries.yml
---
# Copyright 2019, VEXXHOST, 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: Creating temporary directory for Core modules
  tempfile:
    state: directory
    suffix: murano
  register: murano_repo

- name: Clone murano repo
  git:
    dest: "{{ murano_repo.path }}/murano"
    repo: "{{ murano_git_repo }}"
    version: "{{ murano_git_install_branch }}"

- name: Pack common libraries
  archive:
    format: zip
    path: "{{ murano_repo.path }}/murano/meta/{{ item }}/*"
    dest: "{{ murano_repo.path }}/{{ item }}.zip"
  with_items:
    - io.murano
    - io.murano.applications

- name: Import packed libraries
  shell: "{{ murano_bin }}/murano {{ keystone_service_publicuri_insecure | ternary('--insecure', '') }} package-import --exists-action u --is-public {{ murano_repo.path }}/{{ item }}.zip"
  environment:
    OS_USERNAME: "{{ murano_service_user_name }}"
    OS_PASSWORD: "{{ murano_service_password }}"
    OS_PROJECT_NAME: "{{ murano_service_project_name }}"
    OS_AUTH_URL: "{{ keystone_service_adminurl }}"
    OS_USER_DOMAIN_ID: "{{ murano_service_user_domain_id }}"
    OS_PROJECT_DOMAIN_ID: "{{ murano_service_project_domain_id }}"
    OS_REGION_NAME: "{{ murano_service_region }}"
  with_items:
    - io.murano
    - io.murano.applications

- name: Drop temporary directory
  file:
    path: "{{ murano_repo.path }}"
    state: "absent"

- name: Record core libraries installed
  ini_file:
    dest: "/etc/ansible/facts.d/openstack_ansible.fact"
    section: "murano"
    option: "murano_library_installed"
    value: "True"