diff --git a/changelogs/fragments/47462-fix-redfish_config-idempotency.yaml b/changelogs/fragments/47462-fix-redfish_config-idempotency.yaml new file mode 100644 index 00000000000..f7529ffab27 --- /dev/null +++ b/changelogs/fragments/47462-fix-redfish_config-idempotency.yaml @@ -0,0 +1,2 @@ +bugfixes: +- "Fix idempotency issues when setting BIOS attributes via redfish_config module (https://github.com/ansible/ansible/pull/47462)" diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index b76232cb61f..0f98139b089 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -663,6 +663,15 @@ class RedfishUtils(object): return response 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"} + + # 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"} + set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"]["@odata.id"] # Example: bios_attr = {\"name\":\"value\"} @@ -671,7 +680,7 @@ class RedfishUtils(object): response = self.patch_request(self.root_uri + set_bios_attr_uri, payload, HEADERS) if response['ret'] is False: return response - return {'ret': True} + return {'ret': True, 'changed': True, 'msg': "Modified BIOS attribute"} def create_bios_config_job(self): result = {} diff --git a/lib/ansible/modules/remote_management/redfish/redfish_command.py b/lib/ansible/modules/remote_management/redfish/redfish_command.py index 0ae4603f7ad..6508d5e9948 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_command.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_command.py @@ -249,7 +249,6 @@ def main(): # Return data back or fail with proper message if result['ret'] is True: del result['ret'] - result['changed'] = True module.exit_json(changed=True, msg='Action was successful') else: module.fail_json(msg=to_native(result['msg'])) diff --git a/lib/ansible/modules/remote_management/redfish/redfish_config.py b/lib/ansible/modules/remote_management/redfish/redfish_config.py index b3025a284d2..51aa8f18c61 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_config.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_config.py @@ -227,8 +227,7 @@ def main(): # Return data back or fail with proper message if result['ret'] is True: - del result['ret'] - module.exit_json(changed=True, msg='Action was successful') + module.exit_json(changed=result['changed'], msg=to_native(result['msg'])) else: module.fail_json(msg=to_native(result['msg']))