---
- 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_default.yml normally
  tags:
    - 'tests::slow'
  import_playbook: tests_default.yml

- name: Run tests_default.yml in check_mode
  hosts: all
  tags:
    - 'tests::slow'
  tasks:
    - name: Run ansible-playbook with tests_default.yml in check mode
      command: >
        ansible-playbook -vvv -i {{ tempinventory.path }}
        --check tests_default.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
