diff --git a/plugins/httpapi/aci.py b/plugins/httpapi/aci.py index 0275770c0..489797d25 100644 --- a/plugins/httpapi/aci.py +++ b/plugins/httpapi/aci.py @@ -92,10 +92,7 @@ def login(self, username, password): self.connection._connected = True try: response, response_data = self.connection.send(path, data, method=method) - response_value = self._get_response_value(response_data) - self.connection._auth = { - "Cookie": "APIC-Cookie={0}".format(self._response_to_json(response_value).get("imdata")[0]["aaaLogin"]["attributes"]["token"]) - } + self.connection._auth = {"Cookie": response.headers.get("Set-Cookie")} self.connection.queue_message("debug", "Connection to {0} was successful".format(self.connection.get_option("host"))) except Exception as exc_login: self.connection._connected = False diff --git a/plugins/module_utils/aci.py b/plugins/module_utils/aci.py index 06dc58f42..21740e9bb 100644 --- a/plugins/module_utils/aci.py +++ b/plugins/module_utils/aci.py @@ -606,10 +606,14 @@ def response_json(self, rawoutput): return # Extract JSON API output - self.imdata = jsondata.get("imdata") - if self.imdata is None: - self.imdata = dict() - self.totalCount = int(jsondata.get("totalCount")) + if isinstance(jsondata, list): + self.imdata = jsondata + self.totalCount = len(jsondata) + else: + self.imdata = jsondata.get("imdata", {}) + total_count = jsondata.get("totalCount") + if total_count is not None: + self.totalCount = int(total_count) # Handle possible APIC error information self.response_error() diff --git a/plugins/modules/aci_rest.py b/plugins/modules/aci_rest.py index de385c86c..97311df9f 100644 --- a/plugins/modules/aci_rest.py +++ b/plugins/modules/aci_rest.py @@ -316,14 +316,15 @@ def add_annotation(annotation, payload): for key, val in payload.items(): if key in ANNOTATION_UNSUPPORTED: continue - att = val.get("attributes", {}) - if "annotation" not in att.keys(): - att["annotation"] = annotation - # Recursively add annotation to children - children = val.get("children", None) - if children: - for child in children: - add_annotation(annotation, child) + if isinstance(val, dict): + att = val.get("attributes", {}) + if "annotation" not in att.keys(): + att["annotation"] = annotation + # Recursively add annotation to children + children = val.get("children", None) + if children: + for child in children: + add_annotation(annotation, child) def add_annotation_xml(annotation, tree): diff --git a/tests/integration/targets/aci_rest/tasks/json_inline.yml b/tests/integration/targets/aci_rest/tasks/json_inline.yml index 74711ffed..6e60bf26e 100644 --- a/tests/integration/targets/aci_rest/tasks/json_inline.yml +++ b/tests/integration/targets/aci_rest/tasks/json_inline.yml @@ -337,4 +337,28 @@ - nm_add_tenant_annotation_children.imdata.0.fvTenant.attributes.annotation == "test:inoption" - nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.attributes.annotation == "test:inoption" - nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.children.0.fvAEPg.attributes.annotation == "test:inchild" - - nm_add_tenant_annotation_children.imdata.0.fvTenant.children.2.fvCtx.attributes.annotation == "test:inoption" \ No newline at end of file + - nm_add_tenant_annotation_children.imdata.0.fvTenant.children.2.fvCtx.attributes.annotation == "test:inoption" + +# Test to check the fix for disabling intersight connectivity issue: https://github.com/CiscoDevNet/ansible-aci/issues/685 +- name: Disable Intersight Connectivity + cisco.aci.aci_rest: + host: '{{ aci_hostname }}' + username: '{{ aci_username }}' + password: '{{ aci_password }}' + validate_certs: '{{ aci_validate_certs | default(false) }}' + use_ssl: '{{ aci_use_ssl | default(true) }}' + use_proxy: '{{ aci_use_proxy | default(true) }}' + output_level: '{{ aci_output_level | default("info") }}' + path: /connector/Systems.json + method: post + rsp_subtree_preserve: true + content: + { + "AdminState": false + } + register: disable_intersight_connectivity + +- name: Verify Intersight Connectivity is disabled + assert: + that: + - disable_intersight_connectivity.imdata.0.AdminState == false