---
- include: ovb-create-stack.yml
  when: not use_testenv_broker|default(false)|bool

- include: prepare-slave.yml
  when: use_testenv_broker|default(false)|bool

- name: Inventory the undercloud instance
  hosts: localhost
  gather_facts: true
  roles:
    - tripleo-inventory

- name: Setup the undercloud
  hosts: undercloud
  gather_facts: true
  roles:
    - undercloud-setup
  tasks:
    - name: Add eth2 interface from eth2.conf
      command: os-net-config -c {{ working_dir }}/eth2.conf -v
      become: true
      when:
        - network_isolation|bool
        - use_testenv_broker|default(false)|bool

    - name: Set DNS servers for OVB clouds - undercloud
      set_fact:
        undercloud_undercloud_nameservers: "{{ custom_nameserver }}"
        cacheable: true

    - name: Set DNS servers for OVB clouds - overcloud
      set_fact:
        overcloud_dns_servers: "{{ custom_nameserver }}"
        cacheable: true

- name: Inventory the undercloud instance
  hosts: localhost
  gather_facts: true
  roles:
    - tripleo-inventory

# Small playbook with logic for when to build images or not.
# The logic there can be completely overridden by setting the
# to_build variable.
- include: to-build-or-not-to-build.yml

- name: Run DLRN gate role and install repo
  hosts: undercloud
  vars:
    artg_compressed_gating_repo: "${HOME}/gating_repo.tar.gz"
    artg_repos_dir: "{{ repo_clone_dir|default('/opt/stack/new') }}"
    ib_create_web_repo: "{{ to_build|bool }}"
  roles:
    - {role: build-test-packages, when: build_test_packages|default(false)|bool}
    - {role: install-built-repo, when: compressed_gating_repo is defined}
  tags:
    - build

- name: Get images for quickstart
  hosts: undercloud
  gather_facts: false
  vars:
    ib_repo_image_inject: "{{ not to_build|bool }}"
    ib_repo_run_live: false
    modify_image_vc_ram: 4096
    modify_image_vc_cpu: 4
    modify_image_vc_verbose: true
  roles:
    - {role: fetch-images,
       when: not to_build|bool}
    - {role: repo-setup,
       repo_inject_image_path: "$HOME/overcloud-full.qcow2",
       repo_run_live: false,
       when: not to_build|bool}
    - {role: repo-setup,
       repo_inject_image_path: "$HOME/ironic-python-agent.initramfs",
       repo_run_live: false,
       initramfs_image: true,
       libguestfs_mode: false,
       when: not to_build|bool}
    - {role: install-built-repo,
       ib_repo_image_path: "$HOME/overcloud-full.qcow2",
       when: compressed_gating_repo is defined and not to_build|bool}
    - {role: install-built-repo,
       ib_repo_image_path: "$HOME/ironic-python-agent.initramfs",
       initramfs_image: true,
       libguestfs_mode: false,
       when: compressed_gating_repo is defined and not to_build|bool}
