From 75688cb632197a934a93e4e3fa31d3d9a3755751 Mon Sep 17 00:00:00 2001 From: Scott Seekamp Date: Wed, 4 Aug 2021 11:53:43 -0600 Subject: [PATCH] redfish_command: allow setting the BootSourceOverrideMode property (#3135) * For #3134 Expose BootOverrideMode parameter to redfish_command to allow setting by user during run. * Fix trailing whitespace * Add changelog fragment to contribution. * Update changelogs/fragments/3135-add-redfish_command-bootoverridemode.yaml Co-authored-by: Felix Fontein * Update plugins/modules/remote_management/redfish/redfish_command.py Co-authored-by: Felix Fontein * Update plugins/modules/remote_management/redfish/redfish_command.py Co-authored-by: Felix Fontein * Update plugins/modules/remote_management/redfish/redfish_command.py Co-authored-by: Felix Fontein * Update plugins/modules/remote_management/redfish/redfish_command.py Co-authored-by: Felix Fontein * Update changelogs/fragments/3135-add-redfish_command-bootoverridemode.yaml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- ...-add-redfish_command-bootoverridemode.yaml | 2 ++ plugins/module_utils/redfish_utils.py | 8 +++++++- .../redfish/redfish_command.py | 20 ++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/3135-add-redfish_command-bootoverridemode.yaml diff --git a/changelogs/fragments/3135-add-redfish_command-bootoverridemode.yaml b/changelogs/fragments/3135-add-redfish_command-bootoverridemode.yaml new file mode 100644 index 0000000000..d1f24d4c24 --- /dev/null +++ b/changelogs/fragments/3135-add-redfish_command-bootoverridemode.yaml @@ -0,0 +1,2 @@ +minor_changes: + - redfish_command - add ``boot_override_mode`` argument to BootSourceOverride commands (https://github.com/ansible-collections/community.general/issues/3134). diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 8d293f0056..94e2c4b7d8 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -1565,6 +1565,7 @@ class RedfishUtils(object): 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 @@ class RedfishUtils(object): 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 @@ class RedfishUtils(object): } } 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 index 01f1fd771d..72392ec9f3 100644 --- a/plugins/modules/remote_management/redfish/redfish_command.py +++ b/plugins/modules/remote_management/redfish/redfish_command.py @@ -86,6 +86,12 @@ options: - 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 @@ EXAMPLES = ''' 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