From e5972ccbab7e813590b760e30a662efa6cbef4be Mon Sep 17 00:00:00 2001 From: Bill Dodd Date: Mon, 10 Jun 2019 02:50:04 -0500 Subject: [PATCH] redfish_command: Avoid power on/off commands if system already in target state (#56069) * avoid power on/off commands if system already in target state * add changelog fragment --- ...56069-make-redfish-power-commands-idempotent.yaml | 3 +++ lib/ansible/module_utils/redfish_utils.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/56069-make-redfish-power-commands-idempotent.yaml diff --git a/changelogs/fragments/56069-make-redfish-power-commands-idempotent.yaml b/changelogs/fragments/56069-make-redfish-power-commands-idempotent.yaml new file mode 100644 index 00000000000..3b25cc1a54d --- /dev/null +++ b/changelogs/fragments/56069-make-redfish-power-commands-idempotent.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- redfish_command - make power commands idempotent (https://github.com/ansible/ansible/issues/55869) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index af71ff10472..5da72747659 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -620,16 +620,21 @@ class RedfishUtils(object): return result def manage_system_power(self, command): - result = {} key = "Actions" # Search for 'key' entry and extract URI from it response = self.get_request(self.root_uri + self.systems_uris[0]) if response['ret'] is False: return response - result['ret'] = True data = response['data'] power_state = data["PowerState"] + + if power_state == "On" and command == 'PowerOn': + return {'ret': True, 'changed': False} + + if power_state == "Off" and command in ['PowerGracefulShutdown', 'PowerForceOff']: + return {'ret': True, 'changed': False} + reset_action = data[key]["#ComputerSystem.Reset"] action_uri = reset_action["target"] allowable_vals = reset_action.get("ResetType@Redfish.AllowableValues", []) @@ -657,8 +662,7 @@ class RedfishUtils(object): response = self.post_request(self.root_uri + action_uri, payload) if response['ret'] is False: return response - result['ret'] = True - return result + return {'ret': True, 'changed': True} def list_users(self): result = {}