---
- name: Run tests_default.yml in check_mode
  hosts: all
# no ssh running in a container build env
  tags:
    - tests::booted
  tasks:
    - name: Run test
      block:
        - name: Create temporary file
          tempfile:
            state: file
            suffix: .yaml
          register: tempinventory

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

        - 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

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