Repository: ansible-collections/community.general

Issue:
Can't use CreateBiosConfigJob command from idrac_redfish_command module
### Summary

I'm trying to create a job for BIOS configuration.

In the documentation example, specified resource_id is System.Embedded.1
https://github.com/ansible-collections/community.general/blob/926c0a71d03a447580b6a034432608c632477059/plugins/modules/remote_management/redfish/idrac_redfish_command.py#L68

When i use this resource, i have an error message : 
> Manager resource System.Embedded.1 not found

explained by:
https://github.com/ansible-collections/community.general/blob/926c0a71d03a447580b6a034432608c632477059/plugins/modules/remote_management/redfish/idrac_redfish_command.py#L201

And of course, if I use iDRAC.embedded.1 which is the actual manager resource ID, task fails with :
> System resource iDRAC.Embedded.1 not found

explained by :
https://github.com/ansible-collections/community.general/blob/926c0a71d03a447580b6a034432608c632477059/plugins/modules/remote_management/redfish/idrac_redfish_command.py#L194




### Issue Type

Bug Report

### Component Name

idrac_redfish_command

### Ansible Version

```console (paste below)
$ ansible --version
ansible 2.10.5
  config file = /home/pyfontan/.ansible.cfg
  configured module search path = ['/home/pyfontan/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/pyfontan/virtualenv/ansible/lib/python3.8/site-packages/ansible
  executable location = /home/pyfontan/virtualenv/ansible/bin/ansible
  python version = 3.8.6 (default, Jan 27 2021, 15:42:20) [GCC 10.2.0]

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```


### OS / Environment

iDRAC 4.32.20.00 on PowerEdge C6525
or
iDRAC 3.21.26.22 on PowerEdge R740xd

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Create BIOS configuration job (schedule BIOS setting update)
  community.general.idrac_redfish_command:
    category: Systems
    command: CreateBiosConfigJob
    #resource_id: "{{asset_system_resource_name}}"
    #resource_id: "System.Embedded.1"
    resource_id: "iDRAC.Embedded.1"
    baseuri: "{{ asset.manager.ip }}"
    username: "{{ asset.manager.user }}"
    password: "{{ asset.manager.password }}"
 ```


### Expected Results

I expect to have a BIOS Job configuration created.

### Actual Results

```console (paste below)

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/remote_management/redfish/idrac_redfish_command.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/remote_management/redfish/idrac_redfish_command.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 @renxulei @tomasg2012 @xmadsen
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Thanks for opening this issue.

The logic in `CreateBiosConfigJob` was created before the `resource_id` property was added and the requirement that the `resource_id` must be specified for data modification requests where there is more than one resource in the collection category (Systems/Managers/Chassis). So now there is a conflict in that command where both `_find_managers_resource()` and `_find_systems_resource()` are both trying to use the `resource_id` property.

To fix this, I think the correct approach is to:

1. Remove the call to `rf_utils._find_managers_resource()` on line 201.
2. Create a new helper method called `managed_by(resource_uri)` in `RedfishUtils` that will use the `ManagedBy` property within `Links` to look up the Manager for the given resource.
3. In `create_bios_config_job()`, call the new `rf_utils.managed_by(resource_uri)` method to get the Manager URI (instead of using `self.manager_uri` on line 118).
@pyfontan is your server a modular chassis/blades? I thought `resource_id`s are needed only on modular systems i.e. M/MX series etc. On `community.general` version 4.1.0 I got it working by not passing any `resource_id` at all. This on r730xd.
@bluikko : As said in the description i had this problem with :

iDRAC 4.32.20.00 on PowerEdge C6525
or
iDRAC 3.21.26.22 on PowerEdge R740xd

> iDRAC 4.32.20.00 on PowerEdge C6525
> or
> iDRAC 3.21.26.22 on PowerEdge R740xd

On my previous generation systems it works when `resource_id` is not specified.
cc @bhavya06 @rajeevkallur
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Files identified in the description:
* [`plugins/modules/idrac_redfish_command.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/idrac_redfish_command.py)

If these files are incorrect, 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/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @jyundt
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/remote_management/redfish/idrac_redfish_command.py b/plugins/modules/remote_management/redfish/idrac_redfish_command.py
--- a/plugins/modules/remote_management/redfish/idrac_redfish_command.py
+++ b/plugins/modules/remote_management/redfish/idrac_redfish_command.py
@@ -192,7 +192,20 @@ def main():
 
     if category == "Systems":
         # execute only if we find a System resource
+        # NOTE: Currently overriding the usage of 'data_modification' due to
+        # how 'resource_id' is processed.  In the case of CreateBiosConfigJob,
+        # we interact with BOTH systems and managers, so you currently cannot
+        # specify a single 'resource_id' to make both '_find_systems_resource'
+        # and '_find_managers_resource' return success.  Since
+        # CreateBiosConfigJob doesn't use the matched 'resource_id' for a
+        # system regardless of what's specified, disabling the 'resource_id'
+        # inspection for the next call allows a specific manager to be
+        # specified with 'resource_id'.  If we ever need to expand the input
+        # to inspect a specific system and manager in parallel, this will need
+        # updates.
+        rf_utils.data_modification = False
         result = rf_utils._find_systems_resource()
+        rf_utils.data_modification = True
         if result['ret'] is False:
             module.fail_json(msg=to_native(result['msg']))
 


Test patch: