From cc180dd59d6d0efa78988d6c440107b4ac51be8b Mon Sep 17 00:00:00 2001 From: akinross Date: Wed, 20 Sep 2023 09:41:22 +0200 Subject: [PATCH] [ignore] move proposed and output_path logic for aci_rest from aci.py to the aci_rest module --- plugins/module_utils/aci.py | 15 --------------- plugins/modules/aci_rest.py | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/plugins/module_utils/aci.py b/plugins/module_utils/aci.py index a984d48a9..276789278 100644 --- a/plugins/module_utils/aci.py +++ b/plugins/module_utils/aci.py @@ -1446,9 +1446,6 @@ def exit_json(self, filter_existing=None, **kwargs): self.result["sent"] = self.config self.result["proposed"] = self.proposed - elif self.__class__.__name__ == "ACIRESTModule" and self.method != "GET": - self.result["proposed"] = self.proposed - self.dump_json() self.result.update(**kwargs) self.module.exit_json(**self.result) @@ -1489,9 +1486,6 @@ def fail_json(self, msg, **kwargs): self.result["sent"] = self.config self.result["proposed"] = self.proposed - elif self.__class__.__name__ == "ACIRESTModule" and self.method != "GET": - self.result["proposed"] = self.proposed - self.result.update(**kwargs) self.module.fail_json(msg=msg, **self.result) @@ -1520,15 +1514,6 @@ def dump_json(self): if self.result.get("changed") is True: json.dump([mo], output_file) - elif self.__class__.__name__ == "ACIRESTModule" and self.method != "GET": - output_path = self.params.get("output_path") - if output_path is not None: - with open(output_path, "a") as output_file: - if self.module.check_mode: - json.dump([self.proposed], output_file) - else: - output_file.write(str(self.proposed)) - def parsed_url_path(self, url): if not HAS_URLPARSE: self.fail_json(msg="urlparse is not installed") diff --git a/plugins/modules/aci_rest.py b/plugins/modules/aci_rest.py index c5739cfbb..d3a01bd56 100644 --- a/plugins/modules/aci_rest.py +++ b/plugins/modules/aci_rest.py @@ -438,11 +438,21 @@ def main(): # Set changed to true so check_mode changed result is behaving similar to non aci_rest modules aci.result["changed"] = True - if payload: + # Only set proposed if we have a payload and thus also only allow output_path if we have a payload + # DELETE and GET do not have a payload + if payload and method == "POST": if rest_type == "json": - aci.proposed = json.loads(payload) - elif rest_type == "xml": - aci.proposed = payload + payload = json.loads(payload) + + aci.result["proposed"] = payload + + output_path = aci.params.get("output_path") + if output_path is not None: + with open(output_path, "a") as output_file: + if aci.module.check_mode: + json.dump([payload], output_file) + else: + output_file.write(str(payload)) # Report success aci.exit_json(**aci.result)