diff --git a/changelogs/fragments/2334-redfish_config-skip-incorrect-attributes.yml b/changelogs/fragments/2334-redfish_config-skip-incorrect-attributes.yml new file mode 100644 index 0000000000..2e609c43fc --- /dev/null +++ b/changelogs/fragments/2334-redfish_config-skip-incorrect-attributes.yml @@ -0,0 +1,4 @@ +minor_changes: + - redfish_utils module utils - modified set_bios_attributes function to skip invalid attribute instead of returning. Added skipped attributes to output (https://github.com/ansible-collections/community.general/issues/1995). + - idrac_redfish_config - modified set_manager_attributes function to skip invalid attribute instead of returning. Added skipped attributes to output. Modified module exit to add warning variable (https://github.com/ansible-collections/community.general/issues/1995). + - redfish_config - modified module exit to add warning variable (https://github.com/ansible-collections/community.general/issues/1995). diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index d8cc4061f8..df7011a0b4 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -1671,19 +1671,31 @@ class RedfishUtils(object): # Make a copy of the attributes dict attrs_to_patch = dict(attributes) + # List to hold attributes not found + attrs_bad = {} # Check the attributes - for attr in attributes: - if attr not in data[u'Attributes']: - return {'ret': False, 'msg': "BIOS attribute %s not found" % attr} + for attr_name, attr_value in attributes.items(): + # Check if attribute exists + if attr_name not in data[u'Attributes']: + # Remove and proceed to next attribute if this isn't valid + attrs_bad.update({attr_name: attr_value}) + del attrs_to_patch[attr_name] + continue + # If already set to requested value, remove it from PATCH payload - if data[u'Attributes'][attr] == attributes[attr]: - del attrs_to_patch[attr] + if data[u'Attributes'][attr_name] == attributes[attr_name]: + del attrs_to_patch[attr_name] + + warning = "" + if attrs_bad: + warning = "Incorrect attributes %s" % (attrs_bad) # 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"} + 'msg': "BIOS attributes already set", + 'warning': warning} # Get the SettingsObject URI set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"]["@odata.id"] @@ -1693,7 +1705,9 @@ class RedfishUtils(object): response = self.patch_request(self.root_uri + set_bios_attr_uri, payload) if response['ret'] is False: return response - return {'ret': True, 'changed': True, 'msg': "Modified BIOS attribute"} + return {'ret': True, 'changed': True, + 'msg': "Modified BIOS attributes %s" % (attrs_to_patch), + 'warning': warning} def set_boot_order(self, boot_list): if not boot_list: diff --git a/plugins/modules/remote_management/redfish/idrac_redfish_config.py b/plugins/modules/remote_management/redfish/idrac_redfish_config.py index e27ef6a2a6..b16401311b 100644 --- a/plugins/modules/remote_management/redfish/idrac_redfish_config.py +++ b/plugins/modules/remote_management/redfish/idrac_redfish_config.py @@ -179,6 +179,7 @@ class IdracRedfishUtils(RedfishUtils): attrs_to_patch = {} attrs_skipped = {} + attrs_bad = {} # Store attrs which were not found in the system # Search for key entry and extract URI from it response = self.get_request(self.root_uri + manager_uri + "/" + key) @@ -189,13 +190,15 @@ class IdracRedfishUtils(RedfishUtils): if key not in data: return {'ret': False, - 'msg': "%s: Key %s not found" % (command, key)} + 'msg': "%s: Key %s not found" % (command, key), + 'warning': ""} for attr_name, attr_value in attributes.items(): # Check if attribute exists if attr_name not in data[u'Attributes']: - return {'ret': False, - 'msg': "%s: Manager attribute %s not found" % (command, attr_name)} + # Skip and proceed to next attribute if this isn't valid + attrs_bad.update({attr_name: attr_value}) + continue # Find out if value is already set to what we want. If yes, exclude # those attributes @@ -204,16 +207,23 @@ class IdracRedfishUtils(RedfishUtils): else: attrs_to_patch.update({attr_name: attr_value}) + warning = "" + if attrs_bad: + warning = "Incorrect attributes %s" % (attrs_bad) + if not attrs_to_patch: return {'ret': True, 'changed': False, - 'msg': "Manager attributes already set"} + 'msg': "No changes made. Manager attributes already set.", + 'warning': warning} payload = {"Attributes": attrs_to_patch} response = self.patch_request(self.root_uri + manager_uri + "/" + key, payload) if response['ret'] is False: return response + return {'ret': True, 'changed': True, - 'msg': "%s: Modified Manager attributes %s" % (command, attrs_to_patch)} + 'msg': "%s: Modified Manager attributes %s" % (command, attrs_to_patch), + 'warning': warning} CATEGORY_COMMANDS_ALL = { @@ -221,6 +231,7 @@ CATEGORY_COMMANDS_ALL = { "SetSystemAttributes"] } + # list of mutually exclusive commands for a category CATEGORY_COMMANDS_MUTUALLY_EXCLUSIVE = { "Manager": [["SetManagerAttributes", "SetLifecycleControllerAttributes", @@ -308,6 +319,9 @@ def main(): # Return data back or fail with proper message if result['ret'] is True: + if result.get('warning'): + module.warn(to_native(result['warning'])) + module.exit_json(changed=result['changed'], msg=to_native(result['msg'])) else: module.fail_json(msg=to_native(result['msg'])) diff --git a/plugins/modules/remote_management/redfish/redfish_config.py b/plugins/modules/remote_management/redfish/redfish_config.py index 5c1df16c4e..e084c670f4 100644 --- a/plugins/modules/remote_management/redfish/redfish_config.py +++ b/plugins/modules/remote_management/redfish/redfish_config.py @@ -321,6 +321,9 @@ def main(): # Return data back or fail with proper message if result['ret'] is True: + if result.get('warning'): + module.warn(to_native(result['warning'])) + module.exit_json(changed=result['changed'], msg=to_native(result['msg'])) else: module.fail_json(msg=to_native(result['msg']))