Repository: ansible-collections/community.general

Issue:
redfish_utils.py set_manager_nic IndexError: list index out of range
##### SUMMARY
Trying to disable DHCP on a fresh HPE iLO and assign a static IP via SetManagerNic throws an out of index error.

This is my task:
```
  - name: Set Manager NIC
    community.general.redfish_config:
      category: Manager
      command: SetManagerNic
      nic_config:
        DHCPv4:
          DHCPEnabled: False
        IPv4StaticAddresses:
          Address: xxx.xxx.xxx.xxx
          Gateway: xxx.xxx.xxx.xxx
          SubnetMask: xxx.xxx.xxx.xxx
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
```


In reality Redfish returns empty list:

```
    "IPv4Addresses": [
        {
            "Address": "xxx.xxx.xxx.xxx",
            "AddressOrigin": "DHCP",
            "Gateway": "xxx.xxx.xxx.xxx",
            "SubnetMask": "xxx.xxx.xxx.xxx"
        }
    ],
    "IPv4StaticAddresses": [],            <-------- here
```

I've hacked around this by commenting out property check and adding try/except:

~/.ansible/collections/ansible_collections/community/general/plugins/module_utils/redfish_utils.py

```
            # type is list
            if isinstance(set_value, list):
                for i in range(len(set_value)):
                    for subprop in payload[property][i].keys():
                        #if subprop not in target_ethernet_current_setting[property][i]:
                        #    return {'ret': False, 'msg': "Sub-property %s in nic_config is invalid" % subprop}
                        sub_set_value = payload[property][i][subprop]
                        try:
                            sub_cur_value = target_ethernet_current_setting[property][i][subprop]
                        except (KeyError, IndexError):
                            sub_cur_value = ''
                        if sub_set_value != sub_cur_value:
                            need_change = True
```

I'm not sure if the check is needed at all. Trying to set invalid property returns error:

```
FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "HTTP Error 400 on PATCH request to 'https://xxx.xxx.xxx.xxx/redfish/v1/Managers/1/EthernetInterfaces/1/', extended message: 'Bad Request'"}
````


##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
https://github.com/ansible-collections/community.general/blob/main/plugins/module_utils/redfish_utils.py#L2681

and 

https://github.com/ansible-collections/community.general/blob/main/plugins/module_utils/redfish_utils.py#L2684

##### ANSIBLE VERSION

```
ansible 2.9.14
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/lukaszkurdziel/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.9 (default, Aug 19 2020, 17:05:11) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
```


##### CONFIGURATION
Default. Not related.

##### OS / ENVIRONMENT
Fedora. Not related.


##### STEPS TO REPRODUCE
Try to change DHCP HPE iLO default config to static IP.

##### EXPECTED RESULTS
DHCP disabled, static IP assigned.


##### ACTUAL RESULTS

```
ansible_collections/community/general/plugins/module_utils/redfish_utils.py\", line 2681, in set_manager_nic\nIndexError: list index out of range
```



Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
!component =plugins/module_utils/redfish_utils.py
Files identified in the description:
* [`plugins/module_utils/redfish_utils.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/module_utils/redfish_utils.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @billdodd @mraineri @tomasg2012
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@lukurde Sorry about the slow response. I looked at our open Redfish issues and noticed that this one seems to have slipped in without my noticing. I will investigate it tomorrow (Thursday, Mar 18).

Resolving patch:
diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py
--- a/plugins/module_utils/redfish_utils.py
+++ b/plugins/module_utils/redfish_utils.py
@@ -2672,6 +2672,10 @@ def set_manager_nic(self, nic_addr, nic_config):
                         need_change = True
             # type is list
             if isinstance(set_value, list):
+                if len(set_value) != len(cur_value):
+                    # if arrays are not the same len, no need to check each element
+                    need_change = True
+                    continue
                 for i in range(len(set_value)):
                     for subprop in payload[property][i].keys():
                         if subprop not in target_ethernet_current_setting[property][i]:


Test patch: