# 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.

- hosts: primary
  tasks:
    - name: Deploy Packages
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/000-install-packages.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Setup Nodes
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/005-setup-nodes.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy clients
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/010-setup-client.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy ingress
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/020-ingress.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy Ceph
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/030-ceph.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Setup openstack namespace for ceph
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/035-ceph-ns-activate.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy MariaDB
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/040-mariadb.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy RabbitMQ
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/050-rabbitmq.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy Memcached
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/060-memcached.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy Keystone
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/070-keystone.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy Ceph RadosGW Endpoints
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/080-ceph-radosgateway.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy Glance
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/090-glance.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy Heat
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/100-heat.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy Compute Kit
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/110-compute-kit.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Create baremetal host aggregate
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/800-create-baremetal-host-aggregate.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Register baremetal nodes
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/810-register-baremetal-nodes.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Create baremetal flavor
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/820-create-baremetal-flavor.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
    - name: Deploy Node
      environment:
        OSH_OPENSTACK_RELEASE: "{{ osh_openstack_release }}"
        OSH_EXTRA_HELM_ARGS: "{{ zuul_osh_extra_helm_args_relative_path | default('') }}"
        OSH_INFRA_PATH: "{{ zuul_osh_infra_relative_path | default('') }}"
        zuul_site_mirror_fqdn: "{{ zuul_site_mirror_fqdn }}"
      shell: |
        set -xe;
        ./tools/deployment/baremetal/900-use-it.sh
      args:
        chdir: "{{ zuul_osh_relative_path | default(zuul.project.src_dir) }}"
