How to make junos_config Ansible module to support non-ASCII characters?

I use the junos_config module in Ansible version 2.2.1.0, which in a nutshell accepts a plain text configuration file and uses it to configure a Juniper network device. It seems like lxml is being used during the process . The problem is that this text file contains a non-ASCII character, and Ansible does not work with the following error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
fatal: [10.10.10.111]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_FZ42iu/ansible_module_junos_config.py\", line 344, in <module>\n    main()\n  File \"/tmp/ansible_FZ42iu/ansible_module_junos_config.py\", line 335, in main\n    run(module, result)\n  File \"/tmp/ansible_FZ42iu/ansible_module_junos_config.py\", line 293, in run\n    return load_config(module, result)\n  File \"/tmp/ansible_FZ42iu/ansible_module_junos_config.py\", line 258, in load_config\n    diff = module.config.load_config(candidate, **kwargs)\n  File \"/tmp/ansible_FZ42iu/ansible_modlib.zip/ansible/module_utils/netcfg.py\", line 58, in load_config\n  File \"/tmp/ansible_FZ42iu/ansible_modlib.zip/ansible/module_utils/junos.py\", line 201, in load_config\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/utils/config.py\", line 388, in load\n    return try_load(rpc_contents, rpc_xattrs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/utils/config.py\", line 350, in try_load\n    got = self.rpc.load_config(rpc_contents, **rpc_xattrs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/rpcmeta.py\", line 79, in load_config\n    rpc.append(E('configuration-text', contents))\n  File \"/usr/local/lib/python2.7/dist-packages/lxml/builder.py\", line 236, in __call__\n    v = t(elem, item)\n  File \"/usr/local/lib/python2.7/dist-packages/lxml/builder.py\", line 185, in add_text\n    elem.text = (elem.text or \"\") + item\n  File \"src/lxml/lxml.etree.pyx\", line 1031, in lxml.etree._Element.text.__set__ (src/lxml/lxml.etree.c:53225)\n  File \"src/lxml/apihelpers.pxi\", line 715, in lxml.etree._setNodeText (src/lxml/lxml.etree.c:24420)\n  File \"src/lxml/apihelpers.pxi\", line 703, in lxml.etree._createTextNode (src/lxml/lxml.etree.c:24283)\n  File \"src/lxml/apihelpers.pxi\", line 1443, in lxml.etree._utf8 (src/lxml/lxml.etree.c:31502)\nValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters\n", "module_stdout": "", "msg": "MODULE FAILURE"}

I tried using junos_config# -*- coding: utf-8 -*- in the module , but that didn't help. I also tried installing Python on .PYTHONIOENCODINGutf8

The configuration file for junos_config can be seen below:

groups {
    replace: classes {
        /* Configured by Ansible £ */
        system {
            login {
                class test {
                    idle-timeout 1;
                    permissions network;
                    allow-commands "show route.*|quit|exit";
                    deny-commands .*;
                }
            }
        }
    }
}

£, Unable to load config: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters.

junos_config ( lxml) , ASCII?

+4
2

, lxml ascii python2, ascii, utf-8 python3. , Ansible-2.2 python-3, , python3 .

+1

, , - , ASCII UTF-8. :

ValueError: XML: Unicode ASCII, NULL-

, .

fooobar.com/questions/1681124/... , . hexdump filename ..

/ gedit. utf-8 ( ).

+2

Source: https://habr.com/ru/post/1681122/


All Articles