# Buggy code
def commit_configuration(
    module, confirm=False, check=False, comment=None, confirm_timeout=None
):
    obj = Element("commit-configuration")
    if confirm:
        SubElement(obj, "confirmed")
    if check:
        SubElement(obj, "check")
    if comment:
        subele = SubElement(obj, "log")
        subele.text = str(comment)
    if confirm_timeout:
        subele = SubElement(obj, "confirm-timeout")
        subele.text = int(confirm_timeout)
    return send_request(module, obj)


# Traceback (TypeError)
TASK [Push Text File configuration] *************************************************************************************************************************************************
task path: /home/<<USERNAME>>/mac/git/net-ops/playbooks/debug_remote.yml:45
<<<JUNOSHOSTNAME>>> using connection plugin netconf
<<<JUNOSHOSTNAME>>> socket_path: /home/<<USERNAME>>/.ansible/pc/e237c9b826
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/junos.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/netconf.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/six/__init__.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/connection.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/six/_six.py
Using module file /home/<<USERNAME>>/ansible/lib/ansible/modules/network/junos/junos_config.py
<<<JUNOSHOSTNAME>>> ESTABLISH LOCAL CONNECTION FOR USER: <<USERNAME>>
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227 `" &amp;&amp; echo ansible-tmp-1494805291.96-145922927788227="` echo /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227 `" ) &amp;&amp; sleep 0'
<<<JUNOSHOSTNAME>>> PUT /tmp/tmp1F61ev TO /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227/junos_config.py
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c 'chmod u+x /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227/ /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227/junos_config.py &amp;&amp; sleep 0'
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c '/usr/bin/python /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227/junos_config.py; rm -rf "/home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ljfH3Z/ansible_module_junos_config.py", line 360, in <module>
main()
File "/tmp/ansible_ljfH3Z/ansible_module_junos_config.py", line 350, in main
diff = configure_device(module, warnings)
File "/tmp/ansible_ljfH3Z/ansible_module_junos_config.py", line 286, in configure_device
return load_config(module, candidate, warnings, **kwargs)
File "/tmp/ansible_ljfH3Z/ansible_modlib.zip/ansible/module_utils/junos.py", line 186, in load_config
File "/tmp/ansible_ljfH3Z/ansible_modlib.zip/ansible/module_utils/junos.py", line 142, in commit_configuration
File "/tmp/ansible_ljfH3Z/ansible_modlib.zip/ansible/module_utils/netconf.py", line 38, in send_request
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1126, in tostring
ElementTree(element).write(file, encoding, method=method)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 820, in write
serialize(write, self._root, encoding, qnames, namespaces)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 939, in _serialize_xml
_serialize_xml(write, e, encoding, qnames, None)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 937, in _serialize_xml
write(_escape_cdata(text, encoding))
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1075, in _escape_cdata
_raise_serialization_error(text)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1052, in _raise_serialization_error
"cannot serialize %r (type %s)" % (text, type(text).__name__)
TypeError: cannot serialize 10 (type int)

fatal: [<<JUNOSHOSTNAME>>]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_ljfH3Z/ansible_module_junos_config.py\", line 360, in <module>\n    main()\n  File \"/tmp/ansible_ljfH3Z/ansible_module_junos_config.py\", line 350, in main\n    diff = configure_device(module, warnings)\n  File \"/tmp/ansible_ljfH3Z/ansible_module_junos_config.py\", line 286, in configure_device\n    return load_config(module, candidate, warnings, **kwargs)\n  File \"/tmp/ansible_ljfH3Z/ansible_modlib.zip/ansible/module_utils/junos.py\", line 186, in load_config\n  File \"/tmp/ansible_ljfH3Z/ansible_modlib.zip/ansible/module_utils/junos.py\", line 142, in commit_configuration\n  File \"/tmp/ansible_ljfH3Z/ansible_modlib.zip/ansible/module_utils/netconf.py\", line 38, in send_request\n  File \"/usr/lib/python2.7/xml/etree/ElementTree.py\", line 1126, in tostring\n    ElementTree(element).write(file, encoding, method=method)\n  File \"/usr/lib/python2.7/xml/etree/ElementTree.py\", line 820, in write\n    serialize(write, self._root, encoding, qnames, namespaces)\n  File \"/usr/lib/python2.7/xml/etree/ElementTree.py\", line 939, in _serialize_xml\n    _serialize_xml(write, e, encoding, qnames, None)\n  File \"/usr/lib/python2.7/xml/etree/ElementTree.py\", line 937, in _serialize_xml\n    write(_escape_cdata(text, encoding))\n  File \"/usr/lib/python2.7/xml/etree/ElementTree.py\", line 1075, in _escape_cdata\n    _raise_serialization_error(text)\n  File \"/usr/lib/python2.7/xml/etree/ElementTree.py\", line 1052, in _raise_serialization_error\n    \"cannot serialize %r (type %s)\" % (text, type(text).__name__)\nTypeError: cannot serialize 10 (type int)\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def commit_configuration(
    module, confirm=False, check=False, comment=None, confirm_timeout=None
):
    obj = Element("commit-configuration")
    if confirm:
        SubElement(obj, "confirmed")
    if check:
        SubElement(obj, "check")
    if comment:
        subele = SubElement(obj, "log")
        subele.text = str(comment)
    if confirm_timeout:
        subele = SubElement(obj, "confirm-timeout")
        subele.text = str(confirm_timeout)
    return send_request(module, obj)