Repository: ansible/ansible

Issue:
junos_config confirm cannot serialize
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
junos_config

##### ANSIBLE VERSION
```
ansible 2.3.0.0
  config file = /mnt/hgfs/USERNAME/git/net-ops/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]

ansible 2.4.0 (devel f9b4499082) last updated 2017/05/15 08:35:53 (GMT +1300)
  config file = /mnt/hgfs/USERNAME/git/net-ops/ansible.cfg
  configured module search path = [u'/home/USERNAME/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/USERNAME/ansible/lib/ansible
  executable location = /home/USERNAME/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### CONFIGURATION

##### OS / ENVIRONMENT
Ubuntu 14.04 (2.3.0.0-1 deb package, 2.4.0 git devel)
MacOS Sierra 10.12.4 (brew 2.3.0.0)

##### SUMMARY
When using confirm: with junos_config, play fails with serialize error
When confim is omitted, configuration is applied

##### STEPS TO REPRODUCE
```yaml
  tasks:
  - name: Push Text File configuration
    junos_config:
      provider: "{{ netconf }}"
      confirm: 10
      src_format: text
      update: replace
      src: "test.conf"
```
These also fail
```
      confirm: '10'
```
```
      confirm: "10"
```

##### EXPECTED RESULTS
Config change commit with a timeout specified by confirm

##### ACTUAL RESULTS
```
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 ~ && sleep 0'
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227 `" && echo ansible-tmp-1494805291.96-145922927788227="` echo /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494805291.96-145922927788227 `" ) && 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 && 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>&1 && 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
}
```



Discussion:
cc @Qalthos @ganeshrn
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py
--- a/lib/ansible/module_utils/junos.py
+++ b/lib/ansible/module_utils/junos.py
@@ -138,7 +138,7 @@ def commit_configuration(module, confirm=False, check=False, comment=None, confi
         subele.text = str(comment)
     if confirm_timeout:
         subele = SubElement(obj, 'confirm-timeout')
-        subele.text = int(confirm_timeout)
+        subele.text = str(confirm_timeout)
     return send_request(module, obj)
 
 def command(module, command, format='text', rpc_only=False):


Test patch: