---
- name: Converge idrac_gather_facts for PCIeDevice component
  hosts: all
  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:
      - PCIeDevice
    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: []

  tasks:

    - name: Find the chassis API
      ansible.builtin.include_tasks:
        ../../tests/asserts/_check_chassis_url.yml

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

    - name: Assert pcie device dict for length
      ansible.builtin.assert:
        that:
          - "{{ pcie_device | length > 0 }}"
      when: pcie_result.status == 200

    - name: Call assertion
      ansible.builtin.include_tasks: ../../tests/asserts/pciedevice_assert.yml
      with_items: "{{ pcie_device }}"
      loop_control:
        loop_var: pci_data
      when: pcie_device | length > 0
