---
- name: Create static inventory from hostvars
  hosts: all
  tags:
    - 'tests::slow'
  tasks:
    - name: Create temporary file
      tempfile:
        state: file
        suffix: .inventory.yaml
      register: tempinventory
      delegate_to: localhost

    - name: Create static inventory from hostvars
      template:
        src: inventory.yaml.j2
        dest: "{{ tempinventory.path }}"
        mode: "0644"
      delegate_to: localhost


- name: Run tests_ssh.yml normally
  tags:
    - 'tests::slow'
  import_playbook: tests_ssh.yml

- name: Run tests_ssh.yml in check_mode
  hosts: all
  tags:
    - 'tests::slow'
  # uncomment the line below if uncommenting it in tests_ssh.yml
  # - 'tests::multihost_localhost'
  tasks:
    - name: Run ansible-playbook with tests_ssh.yml in check mode
      command: |
        ansible-playbook -b -vv -i {{ tempinventory.path }} --check tests_ssh.yml
      delegate_to: localhost
      changed_when: false

    - name: Remove the temporary file
      file:
        path: "{{ tempinventory.path }}"
        state: absent
      when: tempinventory.path is defined
      delegate_to: localhost
