diff --git a/lib/ansible/modules/network/netconf/netconf_config.py b/lib/ansible/modules/network/netconf/netconf_config.py index 6117b8342b..c16ce48ab8 100644 --- a/lib/ansible/modules/network/netconf/netconf_config.py +++ b/lib/ansible/modules/network/netconf/netconf_config.py @@ -252,6 +252,11 @@ from ansible.module_utils.basic import AnsibleModule, env_fallback from ansible.module_utils.connection import Connection, ConnectionError from ansible.module_utils.network.netconf.netconf import get_capabilities, get_config, sanitize_xml +try: + from lxml.etree import tostring +except ImportError: + from xml.etree.ElementTree import tostring + def main(): """ main entry point for module execution @@ -365,7 +370,7 @@ def main(): try: if module.params['backup']: response = get_config(module, target, lock=execute_lock) - before = to_text(response, errors='surrogate_then_replace').strip() + before = to_text(tostring(response), errors='surrogate_then_replace').strip() result['__backup__'] = before.strip() if validate: conn.validate(target)