---
- name: Provision Packet VMs
  hosts: localhost
  gather_facts: false
  become: true
  tasks:
  - name: Create Kubevirt VMs
    import_role:
      name: packet-ci
  - name: Update inventory for Molecule
    meta: refresh_inventory

- name: Wait until SSH is available
  hosts: all
  become: false
  gather_facts: false

  tasks:
    # Check ssh access without relying on python - this is an horrible hack
    # but wait_for_connection does not work without python
    # and 'until' is incompatible with unreachable errors
    # https://github.com/ansible/ansible/issues/78358
  - name: Wait until SSH is available
    command: >
      ssh -i "{{ lookup('env', 'ANSIBLE_PRIVATE_KEY_FILE') }}"
      -o StrictHostKeyChecking=no
      -o UserKnownHostsFile=/dev/null
      -o ConnectTimeout=3 "{{ lookup('env', 'ANSIBLE_REMOTE_USER') }}@{{ ansible_host }}"
    register: ssh_command
    delay: 0
    until: ssh_command.rc != 255
    retries: 60
    delegate_to: localhost
