Repository: ansible-collections/community.general

Issue:
Expose BootOverrideMode parameter to redfish_command
### Summary

Defined in Redfish 2017.0:

The BootOverrideMode property allows selecting between Legacy/UEFI when using BootSourceOverride settings. This allows intentionally setting the boot mode instead of using whatever may be set on the system at the time.

### Issue Type

Feature Idea

### Component Name

redfish_utils

### Additional Information

redfish_utils.py and redfish_command.py would need minor updates to allow setting this parameter. If not set, can fall back to current behavior of letting the system decide.

### Code of Conduct

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


Discussion:
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)
* [`plugins/modules/remote_management/redfish/redfish_command.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/remote_management/redfish/redfish_command.py)
* [`plugins/modules/remote_management/redfish/redfish_config.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/remote_management/redfish/redfish_config.py)
* [`plugins/modules/remote_management/redfish/redfish_info.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/remote_management/redfish/redfish_info.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 @mraineri @renxulei @tomasg2012 @xmadsen
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Thanks for the suggestion. Just for clarity for others, this would be added to the `SetOneTimeBoot` and `EnableContinuousBootOverride` commands where the user may want to specify UEFI vs legacy as part of the boot override request. `DisableBootOverride` simply shuts off the boot override, so I don't see a need to add this parameter there.

I agree keeping this optional is desired; if the service does not support the property or if it's already configured to some value, there is no need to change it if not requested to do so.
I will have a PR coming soon if that sound reasonable?
Sounds great! Thanks for volunteering!
PR Created: https://github.com/ansible-collections/community.general/pull/3135

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
@@ -1565,6 +1565,7 @@ def set_boot_override(self, boot_opts):
         uefi_target = boot_opts.get('uefi_target')
         boot_next = boot_opts.get('boot_next')
         override_enabled = boot_opts.get('override_enabled')
+        boot_override_mode = boot_opts.get('boot_override_mode')
 
         if not bootdevice and override_enabled != 'Disabled':
             return {'ret': False,
@@ -1596,6 +1597,10 @@ def set_boot_override(self, boot_opts):
         target = boot.get('BootSourceOverrideTarget')
         cur_uefi_target = boot.get('UefiTargetBootSourceOverride')
         cur_boot_next = boot.get('BootNext')
+        cur_override_mode = boot.get('BootSourceOverrideMode')
+
+        if not boot_override_mode:
+            boot_override_mode = cur_override_mode
 
         if override_enabled == 'Disabled':
             payload = {
@@ -1632,12 +1637,13 @@ def set_boot_override(self, boot_opts):
                 }
             }
         else:
-            if cur_enabled == override_enabled and target == bootdevice:
+            if cur_enabled == override_enabled and target == bootdevice and cur_override_mode == boot_override_mode:
                 # If properties are already set, no changes needed
                 return {'ret': True, 'changed': False}
             payload = {
                 'Boot': {
                     'BootSourceOverrideEnabled': override_enabled,
+                    'BootSourceOverrideMode': boot_override_mode,
                     'BootSourceOverrideTarget': bootdevice
                 }
             }
diff --git a/plugins/modules/remote_management/redfish/redfish_command.py b/plugins/modules/remote_management/redfish/redfish_command.py
--- a/plugins/modules/remote_management/redfish/redfish_command.py
+++ b/plugins/modules/remote_management/redfish/redfish_command.py
@@ -86,6 +86,12 @@
       - Timeout in seconds for URL requests to OOB controller
     default: 10
     type: int
+  boot_override_mode:
+    description:
+      - Boot mode when using an override.
+    type: str
+    choices: [ Legacy, UEFI ]
+    version_added: 3.5.0
   uefi_target:
     required: false
     description:
@@ -287,6 +293,16 @@
       username: "{{ username }}"
       password: "{{ password }}"
 
+  - name: Set one-time boot to BiosSetup
+    community.general.redfish_command:
+      category: Systems
+      command: SetOneTimeBoot
+      bootnext: BiosSetup
+      boot_override_mode: Legacy
+      baseuri: "{{ baseuri }}"
+      username: "{{ username }}"
+      password: "{{ password }}"
+
   - name: Disable persistent boot device override
     community.general.redfish_command:
       category: Systems
@@ -591,6 +607,7 @@ def main():
             timeout=dict(type='int', default=10),
             uefi_target=dict(),
             boot_next=dict(),
+            boot_override_mode=dict(choices=['Legacy', 'UEFI']),
             resource_id=dict(),
             update_image_uri=dict(),
             update_protocol=dict(),
@@ -662,7 +679,8 @@ def main():
     boot_opts = {
         'bootdevice': module.params['bootdevice'],
         'uefi_target': module.params['uefi_target'],
-        'boot_next': module.params['boot_next']
+        'boot_next': module.params['boot_next'],
+        'boot_override_mode': module.params['boot_override_mode'],
     }
 
     # VirtualMedia options


Test patch: