---
- name: Test support for autoinstall of cockpit-session-recording
  hosts: all
  tasks:
    - name: Test setup and check for ostree
      include_tasks: tasks/setup.yml
      vars:
        __tlog_unsupported_ostree: true

    - name: Get the rpm package facts
      package_facts:

    - name: Record cockpit installation status
      set_fact:
        cockpit_installed: "{{ 'cockpit' in ansible_facts.packages }}"

    - name: Remove cockpit if installed
      package:
        name: cockpit
        state: absent

    - name: Test role without cockpit
      import_role:
        name: fedora.linux_system_roles.tlog

    - name: Get the rpm package facts without cockpit installed
      package_facts:

    - name: Check that cockpit-session-recording is not installed
      assert:
        that: "'cockpit-session-recording' not in ansible_facts.packages"

    - name: Install cockpit
      package:
        name: cockpit
        state: present

    - name: Test role with cockpit
      import_role:
        name: fedora.linux_system_roles.tlog

    - name: Get the rpm package facts with cockpit installed
      package_facts:

    - name: Check that cockpit-session-recording is installed
      assert:
        that: "'cockpit-session-recording' in ansible_facts.packages"

    - name: Return Cockpit to previous install state
      package:
        name: cockpit
        state: absent
      when: not cockpit_installed
