---
- hosts: primary
  environment:
    KAYOBE_CONFIG_SOURCE_PATH: "{{ kayobe_config_src_dir }}"
    # Don't provision a seed VM - use the Zuul VM as the seed host.
    KAYOBE_SEED_VM_PROVISION: 0
  tasks:
    - name: Ensure seed is deployed
      shell:
        cmd: "{{ kayobe_src_dir }}/dev/seed-deploy.sh &> {{ logs_dir }}/ansible/seed-deploy"
        executable: /bin/bash

    - block:
        # NOTE(mgoddard): The stack user cannot read the kolla source code, which
        # lives in the zuul user's home directory. Copy it to a readable location.
        - name: Create a readable copy of kolla source code
          become: true
          copy:
            src: "{{ ansible_env.PWD ~ '/' ~ zuul.projects['opendev.org/openstack/kolla'].src_dir }}"
            dest: /tmp
            owner: stack
            group: stack
            remote_src: true

        - name: Ensure seed container images are built
          shell:
            cmd: >
              source {{ kayobe_src_dir }}/dev/environment-setup.sh &&
              kayobe seed container image build {{ seed_container_image_regex | default('') }} &> {{ logs_dir }}/ansible/seed-container-image-build
            executable: /bin/bash

        - name: Ensure overcloud container images are built
          shell:
            cmd: >
              source {{ kayobe_src_dir }}/dev/environment-setup.sh &&
              kayobe overcloud container image build {{ overcloud_container_image_regex | default('') }} &> {{ logs_dir }}/ansible/overcloud-container-image-build
            executable: /bin/bash
      when: build_images | bool