---
- name: Create static inventory from hostvars
  tags:
    - 'tests::slow'
  hosts: all
  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
  tags:
    - 'tests::slow'
  hosts: all
  tasks:
    - name: Run ansible-playbook with tests_default.yml in check mode
      command: >-
        {{ __ap_cmd | quote }} -vvv -i {{ tempinventory.path }}
        --check tests_default.yml
      changed_when: false
      delegate_to: localhost
      vars:
        __ap_cmd: "{{ ansible_playbook_filepath | d('ansible-playbook') }}"

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