From 1c37471274573af03f9d1b60ff1913a75629e997 Mon Sep 17 00:00:00 2001 From: Jose Delarosa Date: Mon, 22 Oct 2018 15:33:27 -0500 Subject: [PATCH] Fix idempotency issues in set_bios_attributes - Added check to see if attribute even exists, if not, it exits. - Then checks if attribute is already set to value we want to update it to. If yes, then it exits and changed=False - Otherwise updates the attribute and changed=True --- lib/ansible/module_utils/redfish_utils.py | 11 ++++++++++- .../remote_management/redfish/redfish_command.py | 1 - .../remote_management/redfish/redfish_config.py | 3 +-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 06f0b8e8ad..7ee5f0a1c6 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -701,6 +701,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\"} @@ -709,7 +718,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 0ae4603f7a..6508d5e994 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 b3025a284d..51aa8f18c6 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']))