---
- name: Generate in-memory inventory
  include: openstack.yml

- name: Checkpoint in-memory data into a static inventory
  include: checkpoint.yml

- name: Generate SSH config for accessing hosts via bastion
  include: sshconfig.yml
  when: use_bastion|bool

- name: Configure SSH tunneling to access UI
  include: sshtun.yml
  become: true
  when:
    - use_bastion|bool
    - ui_ssh_tunnel|bool

---
- name: Remove any existing inventory
  file:
    path: "{{ inventory_path }}/hosts"
    state: absent

- name: Refresh the inventory
  meta: refresh_inventory

- name: Generate in-memory inventory
  include: openstack.yml

- name: Checkpoint in-memory data into a static inventory
  include: checkpoint.yml

- name: Generate SSH config for accessing hosts via bastion
  include: sshconfig.yml
  when: use_bastion|bool

- name: Configure SSH tunneling to access UI
  include: sshtun.yml
  become: true
  when:
    - use_bastion|bool
    - ui_ssh_tunnel|bool

Clear the previous inventory during provisioning
Clear the previous inventory during provisioning

If there was a left-over inventory from a previous run that had nodes
which were subsequently removed, these would still show up in the
Ansible's in-memory inventory and Ansible would fail trying to connect
to them.

This is because Ansible automatically loads the `inventory/hosts` file
if it exists and even if we overwrite it later, every node and group
still remains in the memory.

By removing the inventory file and and calling the `refresh_inventory`
meta task, we make sure that any left-over values are removed.
