---
- name: Get system API for controller
  hosts: localhost
  gather_facts: false
  vars:
    hostname: "{{ lookup('env', 'IDRAC_IP') }}"
    username: "{{ lookup('env', 'IDRAC_USER') }}"
    password: "{{ lookup('env', 'IDRAC_PASSWORD') }}"
    idrac_port: "{{ lookup('env', 'IDRAC_PORT') }}"
    validate_certs: false
    target:
      - Controller
    idrac_gather_facts_uri_method: "GET"
    idrac_gather_facts_uri_headers:
      Accept: "application/json"
      Content-Type: "application/json"
      OData-Version: "4.0"
    idrac_gather_facts_uri_body_format: "json"
    idrac_gather_facts_uri_status_code:
      - 200
      - 400
      - 401
      - 404
      - -1
    idrac_gather_facts_uri_return_content: true
    diff_data: {}
    exclude_keys: ["Description"]

  tasks:

    - name: Find the system API
      ansible.builtin.include_tasks:
        ../../tests/asserts/_check_system_url.yml

    - name: Gather Facts for the Controller component
      ansible.builtin.include_role:
        name: "idrac_gather_facts"

    - name: Assert controller dict for length
      ansible.builtin.assert:
        that:
          - "{{ controller | length > 0 }}"
      when: controller_list_temp is defined

    - name: Call assertion
      ansible.builtin.include_tasks: ../../tests/asserts/controller_assert.yml
      when: controller_list_temp is defined
