We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `plugins/modules/idrac_redfish_command.py`
Content:
```
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 
4 # Copyright (c) 2018 Dell EMC Inc.
5 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
6 # SPDX-License-Identifier: GPL-3.0-or-later
7 
8 from __future__ import absolute_import, division, print_function
9 __metaclass__ = type
10 
11 DOCUMENTATION = '''
12 ---
13 module: idrac_redfish_command
14 short_description: Manages Out-Of-Band controllers using iDRAC OEM Redfish APIs
15 description:
16   - Builds Redfish URIs locally and sends them to remote OOB controllers to
17     perform an action.
18   - For use with Dell iDRAC operations that require Redfish OEM extensions.
19 extends_documentation_fragment:
20   - community.general.attributes
21 attributes:
22   check_mode:
23     support: none
24   diff_mode:
25     support: none
26 options:
27   category:
28     required: true
29     description:
30       - Category to execute on iDRAC.
31     type: str
32   command:
33     required: true
34     description:
35       - List of commands to execute on iDRAC.
36     type: list
37     elements: str
38   baseuri:
39     required: true
40     description:
41       - Base URI of iDRAC.
42     type: str
43   username:
44     description:
45       - Username for authenticating to iDRAC.
46     type: str
47   password:
48     description:
49       - Password for authenticating to iDRAC.
50     type: str
51   auth_token:
52     description:
53       - Security token for authenticating to iDRAC.
54     type: str
55     version_added: 2.3.0
56   timeout:
57     description:
58       - Timeout in seconds for HTTP requests to iDRAC.
59     default: 10
60     type: int
61   resource_id:
62     required: false
63     description:
64       - ID of the System, Manager or Chassis to modify.
65     type: str
66     version_added: '0.2.0'
67 
68 author: "Jose Delarosa (@jose-delarosa)"
69 '''
70 
71 EXAMPLES = '''
72   - name: Create BIOS configuration job (schedule BIOS setting update)
73     community.general.idrac_redfish_command:
74       category: Systems
75       command: CreateBiosConfigJob
76       resource_id: System.Embedded.1
77       baseuri: "{{ baseuri }}"
78       username: "{{ username }}"
79       password: "{{ password }}"
80 '''
81 
82 RETURN = '''
83 msg:
84     description: Message with action result or error description
85     returned: always
86     type: str
87     sample: "Action was successful"
88 return_values:
89     description: Dictionary containing command-specific response data from the action.
90     returned: on success
91     type: dict
92     version_added: 6.6.0
93     sample: {
94         "job_id": "/redfish/v1/Managers/iDRAC.Embedded.1/Jobs/JID_471269252011"
95     }
96 '''
97 
98 import re
99 from ansible.module_utils.basic import AnsibleModule
100 from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils
101 from ansible.module_utils.common.text.converters import to_native
102 
103 
104 class IdracRedfishUtils(RedfishUtils):
105 
106     def create_bios_config_job(self):
107         result = {}
108         key = "Bios"
109         jobs = "Jobs"
110 
111         # Search for 'key' entry and extract URI from it
112         response = self.get_request(self.root_uri + self.systems_uris[0])
113         if response['ret'] is False:
114             return response
115         result['ret'] = True
116         data = response['data']
117 
118         if key not in data:
119             return {'ret': False, 'msg': "Key %s not found" % key}
120 
121         bios_uri = data[key]["@odata.id"]
122 
123         # Extract proper URI
124         response = self.get_request(self.root_uri + bios_uri)
125         if response['ret'] is False:
126             return response
127         result['ret'] = True
128         data = response['data']
129         set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"][
130             "@odata.id"]
131 
132         payload = {"TargetSettingsURI": set_bios_attr_uri}
133         response = self.post_request(
134             self.root_uri + self.manager_uri + "/" + jobs, payload)
135         if response['ret'] is False:
136             return response
137 
138         response_output = response['resp'].__dict__
139         job_id_full = response_output["headers"]["Location"]
140         job_id = re.search("JID_.+", job_id_full).group()
141         return {'ret': True, 'msg': "Config job %s created" % job_id, 'job_id': job_id_full}
142 
143 
144 CATEGORY_COMMANDS_ALL = {
145     "Systems": ["CreateBiosConfigJob"],
146     "Accounts": [],
147     "Manager": []
148 }
149 
150 
151 def main():
152     result = {}
153     return_values = {}
154     module = AnsibleModule(
155         argument_spec=dict(
156             category=dict(required=True),
157             command=dict(required=True, type='list', elements='str'),
158             baseuri=dict(required=True),
159             username=dict(),
160             password=dict(no_log=True),
161             auth_token=dict(no_log=True),
162             timeout=dict(type='int', default=10),
163             resource_id=dict()
164         ),
165         required_together=[
166             ('username', 'password'),
167         ],
168         required_one_of=[
169             ('username', 'auth_token'),
170         ],
171         mutually_exclusive=[
172             ('username', 'auth_token'),
173         ],
174         supports_check_mode=False
175     )
176 
177     category = module.params['category']
178     command_list = module.params['command']
179 
180     # admin credentials used for authentication
181     creds = {'user': module.params['username'],
182              'pswd': module.params['password'],
183              'token': module.params['auth_token']}
184 
185     # timeout
186     timeout = module.params['timeout']
187 
188     # System, Manager or Chassis ID to modify
189     resource_id = module.params['resource_id']
190 
191     # Build root URI
192     root_uri = "https://" + module.params['baseuri']
193     rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module,
194                                  resource_id=resource_id, data_modification=True)
195 
196     # Check that Category is valid
197     if category not in CATEGORY_COMMANDS_ALL:
198         module.fail_json(msg=to_native("Invalid Category '%s'. Valid Categories = %s" % (category, list(CATEGORY_COMMANDS_ALL.keys()))))
199 
200     # Check that all commands are valid
201     for cmd in command_list:
202         # Fail if even one command given is invalid
203         if cmd not in CATEGORY_COMMANDS_ALL[category]:
204             module.fail_json(msg=to_native("Invalid Command '%s'. Valid Commands = %s" % (cmd, CATEGORY_COMMANDS_ALL[category])))
205 
206     # Organize by Categories / Commands
207 
208     if category == "Systems":
209         # execute only if we find a System resource
210         result = rf_utils._find_systems_resource()
211         if result['ret'] is False:
212             module.fail_json(msg=to_native(result['msg']))
213 
214         for command in command_list:
215             if command == "CreateBiosConfigJob":
216                 # execute only if we find a Managers resource
217                 result = rf_utils._find_managers_resource()
218                 if result['ret'] is False:
219                     module.fail_json(msg=to_native(result['msg']))
220                 result = rf_utils.create_bios_config_job()
221                 if 'job_id' in result:
222                     return_values['job_id'] = result['job_id']
223 
224     # Return data back or fail with proper message
225     if result['ret'] is True:
226         del result['ret']
227         module.exit_json(changed=True, msg='Action was successful', return_values=return_values)
228     else:
229         module.fail_json(msg=to_native(result['msg']))
230 
231 
232 if __name__ == '__main__':
233     main()
234
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/plugins/modules/idrac_redfish_command.py b/plugins/modules/idrac_redfish_command.py
--- a/plugins/modules/idrac_redfish_command.py
+++ b/plugins/modules/idrac_redfish_command.py
@@ -199,7 +199,20 @@
 
     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']))

{"golden_diff": "diff --git a/plugins/modules/idrac_redfish_command.py b/plugins/modules/idrac_redfish_command.py\n--- a/plugins/modules/idrac_redfish_command.py\n+++ b/plugins/modules/idrac_redfish_command.py\n@@ -199,7 +199,20 @@\n \n     if category == \"Systems\":\n         # execute only if we find a System resource\n+        # NOTE: Currently overriding the usage of 'data_modification' due to\n+        # how 'resource_id' is processed.  In the case of CreateBiosConfigJob,\n+        # we interact with BOTH systems and managers, so you currently cannot\n+        # specify a single 'resource_id' to make both '_find_systems_resource'\n+        # and '_find_managers_resource' return success.  Since\n+        # CreateBiosConfigJob doesn't use the matched 'resource_id' for a\n+        # system regardless of what's specified, disabling the 'resource_id'\n+        # inspection for the next call allows a specific manager to be\n+        # specified with 'resource_id'.  If we ever need to expand the input\n+        # to inspect a specific system and manager in parallel, this will need\n+        # updates.\n+        rf_utils.data_modification = False\n         result = rf_utils._find_systems_resource()\n+        rf_utils.data_modification = True\n         if result['ret'] is False:\n             module.fail_json(msg=to_native(result['msg']))\n", "issue": "Can't use CreateBiosConfigJob command from idrac_redfish_command module\n### Summary\n\nI'm trying to create a job for BIOS configuration.\r\n\r\nIn the documentation example, specified resource_id is System.Embedded.1\r\nhttps://github.com/ansible-collections/community.general/blob/926c0a71d03a447580b6a034432608c632477059/plugins/modules/remote_management/redfish/idrac_redfish_command.py#L68\r\n\r\nWhen i use this resource, i have an error message : \r\n> Manager resource System.Embedded.1 not found\r\n\r\nexplained by:\r\nhttps://github.com/ansible-collections/community.general/blob/926c0a71d03a447580b6a034432608c632477059/plugins/modules/remote_management/redfish/idrac_redfish_command.py#L201\r\n\r\nAnd of course, if I use iDRAC.embedded.1 which is the actual manager resource ID, task fails with :\r\n> System resource iDRAC.Embedded.1 not found\r\n\r\nexplained by :\r\nhttps://github.com/ansible-collections/community.general/blob/926c0a71d03a447580b6a034432608c632477059/plugins/modules/remote_management/redfish/idrac_redfish_command.py#L194\r\n\r\n\r\n\n\n### Issue Type\n\nBug Report\n\n### Component Name\n\nidrac_redfish_command\n\n### Ansible Version\n\n```console (paste below)\r\n$ ansible --version\r\nansible 2.10.5\r\n  config file = /home/pyfontan/.ansible.cfg\r\n  configured module search path = ['/home/pyfontan/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']\r\n  ansible python module location = /home/pyfontan/virtualenv/ansible/lib/python3.8/site-packages/ansible\r\n  executable location = /home/pyfontan/virtualenv/ansible/bin/ansible\r\n  python version = 3.8.6 (default, Jan 27 2021, 15:42:20) [GCC 10.2.0]\r\n\r\n```\r\n\n\n### Configuration\n\n```console (paste below)\r\n$ ansible-config dump --only-changed\r\n\r\n```\r\n\n\n### OS / Environment\n\niDRAC 4.32.20.00 on PowerEdge C6525\r\nor\r\niDRAC 3.21.26.22 on PowerEdge R740xd\n\n### Steps to Reproduce\n\n<!--- Paste example playbooks or commands between quotes below -->\r\n```yaml\r\n- name: Create BIOS configuration job (schedule BIOS setting update)\r\n  community.general.idrac_redfish_command:\r\n    category: Systems\r\n    command: CreateBiosConfigJob\r\n    #resource_id: \"{{asset_system_resource_name}}\"\r\n    #resource_id: \"System.Embedded.1\"\r\n    resource_id: \"iDRAC.Embedded.1\"\r\n    baseuri: \"{{ asset.manager.ip }}\"\r\n    username: \"{{ asset.manager.user }}\"\r\n    password: \"{{ asset.manager.password }}\"\r\n ```\r\n\n\n### Expected Results\n\nI expect to have a BIOS Job configuration created.\n\n### Actual Results\n\n```console (paste below)\r\n\r\n```\r\n\n\n### Code of Conduct\n\n- [X] I agree to follow the Ansible Code of Conduct\n", "before_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# Copyright (c) 2018 Dell EMC Inc.\n# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\nDOCUMENTATION = '''\n---\nmodule: idrac_redfish_command\nshort_description: Manages Out-Of-Band controllers using iDRAC OEM Redfish APIs\ndescription:\n  - Builds Redfish URIs locally and sends them to remote OOB controllers to\n    perform an action.\n  - For use with Dell iDRAC operations that require Redfish OEM extensions.\nextends_documentation_fragment:\n  - community.general.attributes\nattributes:\n  check_mode:\n    support: none\n  diff_mode:\n    support: none\noptions:\n  category:\n    required: true\n    description:\n      - Category to execute on iDRAC.\n    type: str\n  command:\n    required: true\n    description:\n      - List of commands to execute on iDRAC.\n    type: list\n    elements: str\n  baseuri:\n    required: true\n    description:\n      - Base URI of iDRAC.\n    type: str\n  username:\n    description:\n      - Username for authenticating to iDRAC.\n    type: str\n  password:\n    description:\n      - Password for authenticating to iDRAC.\n    type: str\n  auth_token:\n    description:\n      - Security token for authenticating to iDRAC.\n    type: str\n    version_added: 2.3.0\n  timeout:\n    description:\n      - Timeout in seconds for HTTP requests to iDRAC.\n    default: 10\n    type: int\n  resource_id:\n    required: false\n    description:\n      - ID of the System, Manager or Chassis to modify.\n    type: str\n    version_added: '0.2.0'\n\nauthor: \"Jose Delarosa (@jose-delarosa)\"\n'''\n\nEXAMPLES = '''\n  - name: Create BIOS configuration job (schedule BIOS setting update)\n    community.general.idrac_redfish_command:\n      category: Systems\n      command: CreateBiosConfigJob\n      resource_id: System.Embedded.1\n      baseuri: \"{{ baseuri }}\"\n      username: \"{{ username }}\"\n      password: \"{{ password }}\"\n'''\n\nRETURN = '''\nmsg:\n    description: Message with action result or error description\n    returned: always\n    type: str\n    sample: \"Action was successful\"\nreturn_values:\n    description: Dictionary containing command-specific response data from the action.\n    returned: on success\n    type: dict\n    version_added: 6.6.0\n    sample: {\n        \"job_id\": \"/redfish/v1/Managers/iDRAC.Embedded.1/Jobs/JID_471269252011\"\n    }\n'''\n\nimport re\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils\nfrom ansible.module_utils.common.text.converters import to_native\n\n\nclass IdracRedfishUtils(RedfishUtils):\n\n    def create_bios_config_job(self):\n        result = {}\n        key = \"Bios\"\n        jobs = \"Jobs\"\n\n        # Search for 'key' entry and extract URI from it\n        response = self.get_request(self.root_uri + self.systems_uris[0])\n        if response['ret'] is False:\n            return response\n        result['ret'] = True\n        data = response['data']\n\n        if key not in data:\n            return {'ret': False, 'msg': \"Key %s not found\" % key}\n\n        bios_uri = data[key][\"@odata.id\"]\n\n        # Extract proper URI\n        response = self.get_request(self.root_uri + bios_uri)\n        if response['ret'] is False:\n            return response\n        result['ret'] = True\n        data = response['data']\n        set_bios_attr_uri = data[\"@Redfish.Settings\"][\"SettingsObject\"][\n            \"@odata.id\"]\n\n        payload = {\"TargetSettingsURI\": set_bios_attr_uri}\n        response = self.post_request(\n            self.root_uri + self.manager_uri + \"/\" + jobs, payload)\n        if response['ret'] is False:\n            return response\n\n        response_output = response['resp'].__dict__\n        job_id_full = response_output[\"headers\"][\"Location\"]\n        job_id = re.search(\"JID_.+\", job_id_full).group()\n        return {'ret': True, 'msg': \"Config job %s created\" % job_id, 'job_id': job_id_full}\n\n\nCATEGORY_COMMANDS_ALL = {\n    \"Systems\": [\"CreateBiosConfigJob\"],\n    \"Accounts\": [],\n    \"Manager\": []\n}\n\n\ndef main():\n    result = {}\n    return_values = {}\n    module = AnsibleModule(\n        argument_spec=dict(\n            category=dict(required=True),\n            command=dict(required=True, type='list', elements='str'),\n            baseuri=dict(required=True),\n            username=dict(),\n            password=dict(no_log=True),\n            auth_token=dict(no_log=True),\n            timeout=dict(type='int', default=10),\n            resource_id=dict()\n        ),\n        required_together=[\n            ('username', 'password'),\n        ],\n        required_one_of=[\n            ('username', 'auth_token'),\n        ],\n        mutually_exclusive=[\n            ('username', 'auth_token'),\n        ],\n        supports_check_mode=False\n    )\n\n    category = module.params['category']\n    command_list = module.params['command']\n\n    # admin credentials used for authentication\n    creds = {'user': module.params['username'],\n             'pswd': module.params['password'],\n             'token': module.params['auth_token']}\n\n    # timeout\n    timeout = module.params['timeout']\n\n    # System, Manager or Chassis ID to modify\n    resource_id = module.params['resource_id']\n\n    # Build root URI\n    root_uri = \"https://\" + module.params['baseuri']\n    rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module,\n                                 resource_id=resource_id, data_modification=True)\n\n    # Check that Category is valid\n    if category not in CATEGORY_COMMANDS_ALL:\n        module.fail_json(msg=to_native(\"Invalid Category '%s'. Valid Categories = %s\" % (category, list(CATEGORY_COMMANDS_ALL.keys()))))\n\n    # Check that all commands are valid\n    for cmd in command_list:\n        # Fail if even one command given is invalid\n        if cmd not in CATEGORY_COMMANDS_ALL[category]:\n            module.fail_json(msg=to_native(\"Invalid Command '%s'. Valid Commands = %s\" % (cmd, CATEGORY_COMMANDS_ALL[category])))\n\n    # Organize by Categories / Commands\n\n    if category == \"Systems\":\n        # execute only if we find a System resource\n        result = rf_utils._find_systems_resource()\n        if result['ret'] is False:\n            module.fail_json(msg=to_native(result['msg']))\n\n        for command in command_list:\n            if command == \"CreateBiosConfigJob\":\n                # execute only if we find a Managers resource\n                result = rf_utils._find_managers_resource()\n                if result['ret'] is False:\n                    module.fail_json(msg=to_native(result['msg']))\n                result = rf_utils.create_bios_config_job()\n                if 'job_id' in result:\n                    return_values['job_id'] = result['job_id']\n\n    # Return data back or fail with proper message\n    if result['ret'] is True:\n        del result['ret']\n        module.exit_json(changed=True, msg='Action was successful', return_values=return_values)\n    else:\n        module.fail_json(msg=to_native(result['msg']))\n\n\nif __name__ == '__main__':\n    main()\n", "path": "plugins/modules/idrac_redfish_command.py"}], "after_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# Copyright (c) 2018 Dell EMC Inc.\n# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\nDOCUMENTATION = '''\n---\nmodule: idrac_redfish_command\nshort_description: Manages Out-Of-Band controllers using iDRAC OEM Redfish APIs\ndescription:\n  - Builds Redfish URIs locally and sends them to remote OOB controllers to\n    perform an action.\n  - For use with Dell iDRAC operations that require Redfish OEM extensions.\nextends_documentation_fragment:\n  - community.general.attributes\nattributes:\n  check_mode:\n    support: none\n  diff_mode:\n    support: none\noptions:\n  category:\n    required: true\n    description:\n      - Category to execute on iDRAC.\n    type: str\n  command:\n    required: true\n    description:\n      - List of commands to execute on iDRAC.\n    type: list\n    elements: str\n  baseuri:\n    required: true\n    description:\n      - Base URI of iDRAC.\n    type: str\n  username:\n    description:\n      - Username for authenticating to iDRAC.\n    type: str\n  password:\n    description:\n      - Password for authenticating to iDRAC.\n    type: str\n  auth_token:\n    description:\n      - Security token for authenticating to iDRAC.\n    type: str\n    version_added: 2.3.0\n  timeout:\n    description:\n      - Timeout in seconds for HTTP requests to iDRAC.\n    default: 10\n    type: int\n  resource_id:\n    required: false\n    description:\n      - ID of the System, Manager or Chassis to modify.\n    type: str\n    version_added: '0.2.0'\n\nauthor: \"Jose Delarosa (@jose-delarosa)\"\n'''\n\nEXAMPLES = '''\n  - name: Create BIOS configuration job (schedule BIOS setting update)\n    community.general.idrac_redfish_command:\n      category: Systems\n      command: CreateBiosConfigJob\n      resource_id: System.Embedded.1\n      baseuri: \"{{ baseuri }}\"\n      username: \"{{ username }}\"\n      password: \"{{ password }}\"\n'''\n\nRETURN = '''\nmsg:\n    description: Message with action result or error description\n    returned: always\n    type: str\n    sample: \"Action was successful\"\n'''\n\nimport re\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils\nfrom ansible.module_utils.common.text.converters import to_native\n\n\nclass IdracRedfishUtils(RedfishUtils):\n\n    def create_bios_config_job(self):\n        result = {}\n        key = \"Bios\"\n        jobs = \"Jobs\"\n\n        # Search for 'key' entry and extract URI from it\n        response = self.get_request(self.root_uri + self.systems_uris[0])\n        if response['ret'] is False:\n            return response\n        result['ret'] = True\n        data = response['data']\n\n        if key not in data:\n            return {'ret': False, 'msg': \"Key %s not found\" % key}\n\n        bios_uri = data[key][\"@odata.id\"]\n\n        # Extract proper URI\n        response = self.get_request(self.root_uri + bios_uri)\n        if response['ret'] is False:\n            return response\n        result['ret'] = True\n        data = response['data']\n        set_bios_attr_uri = data[\"@Redfish.Settings\"][\"SettingsObject\"][\n            \"@odata.id\"]\n\n        payload = {\"TargetSettingsURI\": set_bios_attr_uri}\n        response = self.post_request(\n            self.root_uri + self.manager_uri + \"/\" + jobs, payload)\n        if response['ret'] is False:\n            return response\n\n        response_output = response['resp'].__dict__\n        job_id = response_output[\"headers\"][\"Location\"]\n        job_id = re.search(\"JID_.+\", job_id).group()\n        # Currently not passing job_id back to user but patch is coming\n        return {'ret': True, 'msg': \"Config job %s created\" % job_id}\n\n\nCATEGORY_COMMANDS_ALL = {\n    \"Systems\": [\"CreateBiosConfigJob\"],\n    \"Accounts\": [],\n    \"Manager\": []\n}\n\n\ndef main():\n    result = {}\n    module = AnsibleModule(\n        argument_spec=dict(\n            category=dict(required=True),\n            command=dict(required=True, type='list', elements='str'),\n            baseuri=dict(required=True),\n            username=dict(),\n            password=dict(no_log=True),\n            auth_token=dict(no_log=True),\n            timeout=dict(type='int', default=10),\n            resource_id=dict()\n        ),\n        required_together=[\n            ('username', 'password'),\n        ],\n        required_one_of=[\n            ('username', 'auth_token'),\n        ],\n        mutually_exclusive=[\n            ('username', 'auth_token'),\n        ],\n        supports_check_mode=False\n    )\n\n    category = module.params['category']\n    command_list = module.params['command']\n\n    # admin credentials used for authentication\n    creds = {'user': module.params['username'],\n             'pswd': module.params['password'],\n             'token': module.params['auth_token']}\n\n    # timeout\n    timeout = module.params['timeout']\n\n    # System, Manager or Chassis ID to modify\n    resource_id = module.params['resource_id']\n\n    # Build root URI\n    root_uri = \"https://\" + module.params['baseuri']\n    rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module,\n                                 resource_id=resource_id, data_modification=True)\n\n    # Check that Category is valid\n    if category not in CATEGORY_COMMANDS_ALL:\n        module.fail_json(msg=to_native(\"Invalid Category '%s'. Valid Categories = %s\" % (category, list(CATEGORY_COMMANDS_ALL.keys()))))\n\n    # Check that all commands are valid\n    for cmd in command_list:\n        # Fail if even one command given is invalid\n        if cmd not in CATEGORY_COMMANDS_ALL[category]:\n            module.fail_json(msg=to_native(\"Invalid Command '%s'. Valid Commands = %s\" % (cmd, CATEGORY_COMMANDS_ALL[category])))\n\n    # Organize by Categories / Commands\n\n    if category == \"Systems\":\n        # execute only if we find a System resource\n        # NOTE: Currently overriding the usage of 'data_modification' due to\n        # how 'resource_id' is processed.  In the case of CreateBiosConfigJob,\n        # we interact with BOTH systems and managers, so you currently cannot\n        # specify a single 'resource_id' to make both '_find_systems_resource'\n        # and '_find_managers_resource' return success.  Since\n        # CreateBiosConfigJob doesn't use the matched 'resource_id' for a\n        # system regardless of what's specified, disabling the 'resource_id'\n        # inspection for the next call allows a specific manager to be\n        # specified with 'resource_id'.  If we ever need to expand the input\n        # to inspect a specific system and manager in parallel, this will need\n        # updates.\n        rf_utils.data_modification = False\n        result = rf_utils._find_systems_resource()\n        rf_utils.data_modification = True\n        if result['ret'] is False:\n            module.fail_json(msg=to_native(result['msg']))\n\n        for command in command_list:\n            if command == \"CreateBiosConfigJob\":\n                # execute only if we find a Managers resource\n                result = rf_utils._find_managers_resource()\n                if result['ret'] is False:\n                    module.fail_json(msg=to_native(result['msg']))\n                result = rf_utils.create_bios_config_job()\n\n    # Return data back or fail with proper message\n    if result['ret'] is True:\n        del result['ret']\n        module.exit_json(changed=True, msg='Action was successful')\n    else:\n        module.fail_json(msg=to_native(result['msg']))\n\n\nif __name__ == '__main__':\n    main()\n", "path": "plugins/modules/idrac_redfish_command.py"}]}