# SPDX-License-Identifier: MIT
---
- name: Basic insights autoupdate test
  hosts: all
  gather_facts: false
  become: true

  tasks:
    - name: Setup Insights
      import_tasks: tasks/setup_insights.yml

    - name: Test autoupdate
      block:
        - name: Add autoupdate and register insights
          include_role:
            name: linux-system-roles.rhc
            public: true
          vars:
            rhc_auth:
              login:
                username: "{{ lsr_rhc_test_data.reg_username }}"
                password: "{{ lsr_rhc_test_data.reg_password }}"
            rhc_insights:
              autoupdate: true
              remediation: absent
              state: present
            rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
            rhc_server:
              hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
              port: "{{ lsr_rhc_test_data.candlepin_port }}"
              prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
              insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
            rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"

        - name: Check that auto_update is true in config file
          command:
            grep -ixq "^auto_update=true" {{ __rhc_insights_conf }}
          changed_when: false

        - name: Disable autoupdate
          include_role:
            name: linux-system-roles.rhc
          vars:
            rhc_insights:
              autoupdate: false
              remediation: absent

        - name: Disable autoupdate (noop)
          include_role:
            name: linux-system-roles.rhc
          vars:
            rhc_insights:
              autoupdate: false
              remediation: absent

        - name: Check that auto_update is false in config file
          command:
            grep -ixq "^auto_update=false" {{ __rhc_insights_conf }}
          changed_when: false

      always:
        - name: Unregister
          include_role:
            name: linux-system-roles.rhc
          vars:
            rhc_state: absent
