diff --git a/lib/ansible/plugins/netconf/__init__.py b/lib/ansible/plugins/netconf/__init__.py index 39af3850ce7..1da58dbf27f 100644 --- a/lib/ansible/plugins/netconf/__init__.py +++ b/lib/ansible/plugins/netconf/__init__.py @@ -29,7 +29,7 @@ from ansible.module_utils.basic import missing_required_lib try: from ncclient.operations import RPCError - from ncclient.xml_ import to_xml, to_ele + from ncclient.xml_ import to_xml, to_ele, NCElement HAS_NCCLIENT = True NCCLIENT_IMP_ERR = None except (ImportError, AttributeError) as err: # paramiko and gssapi are incompatible and raise AttributeError not ImportError @@ -225,7 +225,20 @@ class NetconfBase(AnsiblePlugin): raise ValueError('rpc_command value must be provided') resp = self.m.dispatch(fromstring(rpc_command), source=source, filter=filter) - return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml + + if isinstance(resp, NCElement): + # In case xml reply is transformed or namespace is removed in + # ncclient device specific handler return modified xml response + result = resp.data_xml + elif hasattr(resp, 'data_ele') and resp.data_ele: + # if data node is present in xml response return the xml string + # with data node as root + result = resp.data_xml + else: + # return raw xml string received from host with rpc-reply as the root node + result = resp.xml + + return result @ensure_connected def lock(self, target="candidate"):