[backport 2.7] Fix idempotency issues in set_bios_attributes (#47802)
* 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
(cherry picked from commit 1c37471274
)
* add changelog fragment
This commit is contained in:
parent
8a240ed54d
commit
01c0a6d699
4 changed files with 13 additions and 4 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "Fix idempotency issues when setting BIOS attributes via redfish_config module (https://github.com/ansible/ansible/pull/47462)"
|
|
@ -663,6 +663,15 @@ class RedfishUtils(object):
|
||||||
return response
|
return response
|
||||||
result['ret'] = True
|
result['ret'] = True
|
||||||
data = response['data']
|
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"]
|
set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"]["@odata.id"]
|
||||||
|
|
||||||
# Example: bios_attr = {\"name\":\"value\"}
|
# 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)
|
response = self.patch_request(self.root_uri + set_bios_attr_uri, payload, HEADERS)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
return {'ret': True}
|
return {'ret': True, 'changed': True, 'msg': "Modified BIOS attribute"}
|
||||||
|
|
||||||
def create_bios_config_job(self):
|
def create_bios_config_job(self):
|
||||||
result = {}
|
result = {}
|
||||||
|
|
|
@ -249,7 +249,6 @@ def main():
|
||||||
# Return data back or fail with proper message
|
# Return data back or fail with proper message
|
||||||
if result['ret'] is True:
|
if result['ret'] is True:
|
||||||
del result['ret']
|
del result['ret']
|
||||||
result['changed'] = True
|
|
||||||
module.exit_json(changed=True, msg='Action was successful')
|
module.exit_json(changed=True, msg='Action was successful')
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
|
@ -227,8 +227,7 @@ def main():
|
||||||
|
|
||||||
# Return data back or fail with proper message
|
# Return data back or fail with proper message
|
||||||
if result['ret'] is True:
|
if result['ret'] is True:
|
||||||
del result['ret']
|
module.exit_json(changed=result['changed'], msg=to_native(result['msg']))
|
||||||
module.exit_json(changed=True, msg='Action was successful')
|
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue