- name: Get license information.
  ansible.builtin.uri:
    url: "https://{{ hostname }}/redfish/v1/LicenseService/Licenses/{{ license_data.Id }}"
    validate_certs: "{{ validate_certs }}"
    ca_path: "{{ ca_path | default(omit) }}"
    method: "{{ idrac_gather_facts_uri_method }}"
    user: "{{ username }}"
    password: "{{ password }}"
    headers: "{{ idrac_gather_facts_uri_headers }}"
    body_format: "{{ idrac_gather_facts_uri_body_format }}"
    status_code: "{{ idrac_gather_facts_uri_status_code }}"
    return_content: "{{ idrac_gather_facts_uri_return_content }}"
  register: license_result
  no_log: false

- name: Set license facts
  ansible.builtin.set_fact:
    api_response: "{{ license_result.json | ansible.utils.remove_keys(target=['@odata.context', '@odata.id', '@odata.type']) }}"

- name: Set the keys diff
  ansible.builtin.set_fact:
    diff_keys: "{{ license_data.keys() | list | symmetric_difference((api_response.keys() | list)) }}"

- name: Set a diff of dict
  ansible.builtin.set_fact:
    diff_data: "{{ diff_data | combine({item: license_data[item]}) }}"
  loop: "{{ license_data.keys() }}"
  when:
    - diff_keys | length == 0
    - license_data[item] != api_response[item]
    - item not in exclude_keys

- name: Assert the difference in Keys
  ansible.builtin.assert:
    that:
      - "{{ (diff_keys | length) == 0 }}"
      - "{{ (diff_data | length) == 0 }}"
    fail_msg: "The response from the role does not match | Diff Keys : {{ diff_keys }} Diff Data : {{ diff_data }}"
    success_msg: "The response from the role matches |  Diff Keys : {{ diff_keys }} Diff Data : {{ diff_data }}"
