---
# Add the virthost to the in-memory inventory.  The inventory is not
# wirtten out to disk unless you call the `rebuild-inventory` role.
- name: Add the virthost to the inventory
  hosts: localhost
  tasks:
    - name: Add virthost
      add_host:
        name: "{{ virthost }}"
        groups: "virthost"
        ansible_fqdn: "{{ virthost }}"
        ansible_user: "root"
        ansible_host: "{{ virthost }}"
        ansible_private_key_file: "{{ ansible_private_key_file_location | default('') }}"

- include: teardown-provision.yml

# The `provision.yml` playbook is responsible for
# creating an inventory entry for our `virthost` and for creating an
# unprivileged user on that host for use by our virtual environment.
- include: provision.yml

# These teardown tasks only make sense after running provision.yml,
# because they assume they are connecting as the `stack` user rather
# than `root`.
- include: teardown-nodes.yml
- include: teardown-environment.yml

# The `environment/setup` role performs any tasks that require `root`
# access on the target host.
- name: Install libvirt packages and configure networks
  hosts: virthost
  tags:
    - environment
  roles:
    - environment/setup

- name: Setup undercloud and baremetal vms and networks in libvirt
  hosts: virthost
  gather_facts: true
  roles:
    - libvirt/setup

# Add the undercloud node to the generated
# inventory.
- name: Inventory the undercloud
  hosts: localhost
  gather_facts: true
  vars:
    inventory: undercloud
  roles:
    - tripleo-inventory

- name: Prepare the host for PXE forwarding
  hosts: virthost
  gather_facts: false
  roles:
    - baremetal-prep-virthost

- name: Run DLRN gate role and install repo
  hosts: undercloud
  gather_facts: true
  become: true
  tasks:
    - include_role:
        name: build-test-packages
      vars:
        artg_compressed_gating_repo: "/home/{{ undercloud_user }}/gating_repo.tar.gz"

    - include_role:
        name: install-built-repo
      when: compressed_gating_repo is defined

    - include_role:
        name: install-built-repo
      vars:
        ib_repo_image_path: "/home/{{ undercloud_user }}/overcloud-full.qcow2"
      when: compressed_gating_repo is defined

    - include_role:
        name: install-built-repo
      vars:
        ib_repo_image_path: "/home/{{ undercloud_user }}/ironic-python-agent.initramfs"
        initramfs_image: true
        libguestfs_mode: false
      when: compressed_gating_repo is defined
