diff --git a/plugins/modules/aci_config_snapshot.py b/plugins/modules/aci_config_snapshot.py index 52170ef40..bc36a5e62 100644 --- a/plugins/modules/aci_config_snapshot.py +++ b/plugins/modules/aci_config_snapshot.py @@ -279,8 +279,7 @@ def main(): target_filter={"name": export_policy}, ), ) - # Variable set for reuse of correct url in get_existing() triggered from exit_json() after query request - reset_url = aci.url + aci.get_existing() aci.payload( @@ -305,8 +304,6 @@ def main(): path = "api/node/mo/uni/backupst/jobs-[uni/fabric/configexp-{0}].json".format(export_policy) aci.api_call("GET", url="{0}/{1}".format(aci.base_url, path)) aci.result["job_details"] = aci.existing[0].get("configJobCont", {}) - # Reset state and url to display correct in output and trigger get_existing() function with correct url - aci.url = reset_url else: # Prefix the proper url to export_policy diff --git a/plugins/modules/aci_rest.py b/plugins/modules/aci_rest.py index 374c9206f..ad73cb5bd 100644 --- a/plugins/modules/aci_rest.py +++ b/plugins/modules/aci_rest.py @@ -250,6 +250,7 @@ import json import os +import re try: from ansible.module_utils.six.moves.urllib.parse import parse_qsl, urlencode, urlparse, urlunparse @@ -406,8 +407,11 @@ def main(): module.fail_json(msg="Failed to parse provided XML payload: {0}".format(to_text(e)), payload=payload) # Perform actual request using auth cookie (Same as aci.request(), but also supports XML) - aci.url = "{0}/{1}".format(aci.base_url, path.lstrip("/")) + # NOTE By setting aci.path we ensure that Ansible displays accurate URL info when the plugin and the aci_rest module are used. + aci.path = path.lstrip("/") + aci.url = "{0}/{1}".format(aci.base_url, aci.path) if aci.params.get("method") != "get" and not rsp_subtree_preserve: + aci.path = "{0}?rsp-subtree=modified".format(aci.path) aci.url = update_qsl(aci.url, {"rsp-subtree": "modified"}) method = aci.params.get("method").upper() @@ -434,6 +438,9 @@ def main(): aci.result["totalCount"] = aci.totalCount else: + # NOTE A case when aci_rest is used with check mode and the apic host is used directly from the inventory + if aci.connection is not None and aci.params.get("host") is None: + aci.url = urlunparse(urlparse(aci.url)._replace(netloc=re.sub(r"[[\]]", "", aci.connection.get_option("host")).split(",")[0])) aci.method = method # Set changed to true so check_mode changed result is behaving similar to non aci_rest modules aci.result["changed"] = True