diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 7d4acf0925a..1a5b99dd462 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -1419,7 +1419,7 @@ class RedfishUtils(object): return response return {'ret': True, 'changed': True} - def set_bios_attributes(self, attr): + def set_bios_attributes(self, attributes): result = {} key = "Bios" @@ -1442,19 +1442,27 @@ class RedfishUtils(object): result['ret'] = True data = response['data'] - # First, check if BIOS attribute exists - if attr['bios_attr_name'] not in data[u'Attributes']: - return {'ret': False, 'msg': "BIOS attribute not found"} + # Make a copy of the attributes dict + attrs_to_patch = dict(attributes) - # Find out if value is already set to what we want. If yes, return - if data[u'Attributes'][attr['bios_attr_name']] == attr['bios_attr_value']: - return {'ret': True, 'changed': False, 'msg': "BIOS attribute already set"} + # Check the attributes + for attr in attributes: + if attr not in data[u'Attributes']: + return {'ret': False, 'msg': "BIOS attribute %s not found" % attr} + # If already set to requested value, remove it from PATCH payload + if data[u'Attributes'][attr] == attributes[attr]: + del attrs_to_patch[attr] + # Return success w/ changed=False if no attrs need to be changed + if not attrs_to_patch: + return {'ret': True, 'changed': False, + 'msg': "BIOS attributes already set"} + + # Get the SettingsObject URI set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"]["@odata.id"] - # Example: bios_attr = {\"name\":\"value\"} - bios_attr = "{\"" + attr['bios_attr_name'] + "\":\"" + attr['bios_attr_value'] + "\"}" - payload = {"Attributes": json.loads(bios_attr)} + # Construct payload and issue PATCH command + payload = {"Attributes": attrs_to_patch} response = self.patch_request(self.root_uri + set_bios_attr_uri, payload) if response['ret'] is False: return response diff --git a/lib/ansible/modules/remote_management/redfish/redfish_config.py b/lib/ansible/modules/remote_management/redfish/redfish_config.py index 688cc2bb4d3..4eaf79b7f46 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_config.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_config.py @@ -51,17 +51,24 @@ options: bios_attribute_name: required: false description: - - name of BIOS attribute to update + - name of BIOS attr to update (deprecated - use bios_attributes instead) default: 'null' type: str version_added: "2.8" bios_attribute_value: required: false description: - - value of BIOS attribute to update + - value of BIOS attr to update (deprecated - use bios_attributes instead) default: 'null' type: str version_added: "2.8" + bios_attributes: + required: false + description: + - dictionary of BIOS attributes to update + default: {} + type: dict + version_added: "2.10" timeout: description: - Timeout in seconds for URL requests to OOB controller @@ -90,23 +97,25 @@ EXAMPLES = ''' redfish_config: category: Systems command: SetBiosAttributes - bios_attribute_name: BootMode - bios_attribute_value: Uefi + bios_attributes: + BootMode: "Uefi" baseuri: "{{ baseuri }}" username: "{{ username }}" password: "{{ password }}" - - name: Set BootMode to Legacy BIOS + - name: Set multiple BootMode attributes redfish_config: category: Systems command: SetBiosAttributes - bios_attribute_name: BootMode - bios_attribute_value: Bios + bios_attributes: + BootMode: "Bios" + OneTimeBootMode: "Enabled" + BootSeqRetry: "Enabled" baseuri: "{{ baseuri }}" username: "{{ username }}" password: "{{ password }}" - - name: Enable PXE Boot for NIC1 + - name: Enable PXE Boot for NIC1 using deprecated options redfish_config: category: Systems command: SetBiosAttributes @@ -195,6 +204,7 @@ def main(): password=dict(required=True, no_log=True), bios_attribute_name=dict(default='null'), bios_attribute_value=dict(default='null'), + bios_attributes=dict(type='dict', default={}), timeout=dict(type='int', default=10), boot_order=dict(type='list', elements='str', default=[]), network_protocols=dict( @@ -216,8 +226,13 @@ def main(): timeout = module.params['timeout'] # BIOS attributes to update - bios_attributes = {'bios_attr_name': module.params['bios_attribute_name'], - 'bios_attr_value': module.params['bios_attribute_value']} + bios_attributes = module.params['bios_attributes'] + if module.params['bios_attribute_name'] != 'null': + bios_attributes[module.params['bios_attribute_name']] = module.params[ + 'bios_attribute_value'] + module.deprecate(msg='The bios_attribute_name/bios_attribute_value ' + 'options are deprecated. Use bios_attributes instead', + version='2.10') # boot order boot_order = module.params['boot_order']