{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/36786","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/36786/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/36786/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/36786/events","html_url":"https://github.com/ansible/ansible/issues/36786","id":300678233,"number":36786,"title":"netconf_config module needs to support ncclient device handlers","user":{"login":"mtarking","id":18662173,"avatar_url":"https://avatars2.githubusercontent.com/u/18662173?v=4","gravatar_id":"","url":"https://api.github.com/users/mtarking","html_url":"https://github.com/mtarking","followers_url":"https://api.github.com/users/mtarking/followers","following_url":"https://api.github.com/users/mtarking/following{/other_user}","gists_url":"https://api.github.com/users/mtarking/gists{/gist_id}","starred_url":"https://api.github.com/users/mtarking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtarking/subscriptions","organizations_url":"https://api.github.com/users/mtarking/orgs","repos_url":"https://api.github.com/users/mtarking/repos","events_url":"https://api.github.com/users/mtarking/events{/privacy}","received_events_url":"https://api.github.com/users/mtarking/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-27T15:33:26Z","updated_at":"2018-02-27T15:36:46Z","closed_at":null,"author_association":"NONE","body":"##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\nnetconf_config\r\n\r\n##### ANSIBLE VERSION\r\n```\r\nansible 2.4.3.0\r\n  config file = None\r\n  configured module search path = [u'/home/pod1user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']\r\n  ansible python module location = /home/pod1user/.virtualenvs/ansible/lib/python2.7/site-packages/ansible\r\n  executable location = /home/pod1user/.virtualenvs/ansible/bin/ansible\r\n  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]\r\n```\r\n\r\n##### CONFIGURATION\r\n$ ansible-config dump --only-changed\r\n$ \r\n\r\n##### OS / ENVIRONMENT\r\n$ cat /etc/centos-release\r\nCentOS Linux release 7.3.1611 (Core) \r\n$\r\n\r\n##### SUMMARY\r\nWhen using the netconf_config module in a task where the host is a Cisco Nexus device, this module would fail and timeout with the below error msg and traceback:\r\n```\r\nThe full traceback is:\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_GtNH9A/ansible_module_netconf_config.py\", line 303, in main\r\n    datastore=datastore,\r\n  File \"/tmp/ansible_GtNH9A/ansible_module_netconf_config.py\", line 164, in netconf_edit_config\r\n    m.lock(target=datastore)\r\n  File \"/usr/lib/python2.7/site-packages/ncclient/manager.py\", line 162, in wrapper\r\n    return self.execute(op_cls, *args, **kwds)\r\n  File \"/usr/lib/python2.7/site-packages/ncclient/manager.py\", line 232, in execute\r\n    raise_mode=self._raise_mode).request(*args, **kwds)\r\n  File \"/usr/lib/python2.7/site-packages/ncclient/operations/lock.py\", line 35, in request\r\n    return self._request(node)\r\n  File \"/usr/lib/python2.7/site-packages/ncclient/operations/rpc.py\", line 343, in _request\r\n    raise TimeoutExpiredError('ncclient timed out while waiting for an rpc reply.')\r\nTimeoutExpiredError: ncclient timed out while waiting for an rpc reply.\r\n\r\nfatal: [10.0.249.251]: FAILED! => {\r\n    \"changed\": false, \r\n    \"invocation\": {\r\n        \"module_args\": {\r\n            \"allow_agent\": false, \r\n            \"datastore\": \"running\", \r\n            \"host\": \"10.0.249.251\", \r\n            \"hostkey_verify\": false, \r\n            \"look_for_keys\": false, \r\n            \"password\": \"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER\", \r\n            \"port\": 830, \r\n            \"save\": false, \r\n            \"src\": \"<config>\\n    <System xmlns=\\\"http://cisco.com/ns/yang/cisco-nx-os-device\\\">\\n        <fm-items>\\n            <bgp-items>\\n                <********St>enabled</********St>\\n            </bgp-items>\\n        </fm-items>\\n    </System>\\n</config>\", \r\n            \"username\": \"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER\", \r\n            \"xml\": null\r\n        }\r\n    }, \r\n    \"msg\": \"error editing configuration: ncclient timed out while waiting for an rpc reply.\"\r\n}\r\n```\r\n\r\n##### STEPS TO REPRODUCE\r\nPlaybook execution:\r\n\r\nansible-playbook -i hosts site.yml -vvv\r\n<!--- Paste example playbooks or commands between quotes below -->\r\nAnsible playbook directory layout:\r\n\r\n```\r\n$ tree\r\n.\r\n|-- group_vars\r\n|     |-- all.yml\r\n|-- hosts\r\n|-- roles\r\n|    |-- netconf\r\n|          |-- defaults\r\n|          |     |-- main.yml\r\n|          |-- files\r\n|          |     |-- enable_bgp.xml\r\n|          |-- handlers\r\n|          |     |-- main.yml\r\n|          |-- meta\r\n|          |     |-- main.yml\r\n|          |-- README.md\r\n|          |-- tasks\r\n|          |     |-- main.yml\r\n|          |-- templates\r\n|          |-- tests\r\n|          |    |-- inventory\r\n|          |    |-- test.yml\r\n|          |-- vars\r\n|                |-- main.yml\r\n|-- site.yml\r\n\r\n11 directories, 12 files\r\n```\r\n\r\ngroup_vars/all:\r\n\r\n```yaml\r\n---\r\nansible_connection: local\r\n```\r\n\r\nroles/netconf/files/enable_bgp.xml:\r\n\r\n```xml\r\n<config>\r\n    <System xmlns=\"http://cisco.com/ns/yang/cisco-nx-os-device\">\r\n        <fm-items>\r\n            <bgp-items>\r\n                <adminSt>enabled</adminSt>\r\n            </bgp-items>\r\n        </fm-items>\r\n    </System>\r\n</config>\r\n```\r\n\r\nroles/netconf/tasks/main.yml:\r\n\r\n```yaml\r\n---\r\n# tasks file for netconf\r\n- name: NETCONF ENABLE BGP\r\n  netconf_config:\r\n    host: 10.0.249.251\r\n    port: 830\r\n    username: admin\r\n    password: cisco.123\r\n    look_for_keys: False\r\n    hostkey_verify: False\r\n    allow_agent: False\r\n    datastore: running\r\n    src: /home/pod1user/Devel/ansible/playbooks/netconf/roles/netconf/files/enable_bgp.xml\r\n```\r\n\r\nmain playbook:\r\n\r\n```yaml\r\n---\r\n- hosts: n9kv\r\n  roles:\r\n    - role: netconf\r\n```\r\n\r\n##### EXPECTED RESULTS\r\nThe expected result is a successful rpc to the specified device, not just a Cisco Nexus device. To solve this, some simple modifications can be made to the module params that aligns with ncclient's device handlers. Here's is a recommended solution:\r\n```\r\nmodule = AnsibleModule(\r\n        argument_spec=dict(\r\n            host=dict(type='str', required=True),\r\n            port=dict(type='int', default=830),\r\n            hostkey_verify=dict(type='bool', default=True),\r\n            allow_agent=dict(type='bool', default=True),\r\n            look_for_keys=dict(type='bool', default=True),\r\n            datastore=dict(choices=['auto', 'candidate', 'running'], default='auto'),\r\n            save=dict(type='bool', default=False),\r\n            username=dict(type='str', required=True, no_log=True),\r\n            password=dict(type='str', required=True, no_log=True),\r\n            xml=dict(type='str', required=False),\r\n            src=dict(type='path', required=False),\r\n            device_handler=dict(choices=['junos', 'csr', 'nexus', 'iosxr', 'iosxe', 'huawei', 'alu', 'h3c', 'hpcomware', 'default'], default='default'),\r\n        ),\r\n        mutually_exclusive=[('xml', 'src')]\r\n    )\r\n<snip>\r\nnckwargs = dict(\r\n        host=module.params['host'],\r\n        port=module.params['port'],\r\n        hostkey_verify=module.params['hostkey_verify'],\r\n        allow_agent=module.params['allow_agent'],\r\n        look_for_keys=module.params['look_for_keys'],\r\n        username=module.params['username'],\r\n        password=module.params['password'],\r\n        device_params={'name': module.params['device_handler']}\r\n    )\r\n```\r\n```yaml\r\n---\r\n# tasks file for netconf\r\n- name: NETCONF ENABLE BGP\r\n  netconf_config:\r\n    host: 10.0.249.251\r\n    port: 830\r\n    username: admin\r\n    password: cisco.123\r\n    look_for_keys: False\r\n    hostkey_verify: False\r\n    allow_agent: False\r\n    datastore: running\r\n    device_handler: nexus\r\n    src: /home/pod1user/Devel/ansible/playbooks/netconf/roles/netconf/files/enable_bgp.xml\r\n```\r\n\r\n##### ACTUAL RESULTS\r\nActual results:\r\n```\r\nThe full traceback is:\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_GtNH9A/ansible_module_netconf_config.py\", line 303, in main\r\n    datastore=datastore,\r\n  File \"/tmp/ansible_GtNH9A/ansible_module_netconf_config.py\", line 164, in netconf_edit_config\r\n    m.lock(target=datastore)\r\n  File \"/usr/lib/python2.7/site-packages/ncclient/manager.py\", line 162, in wrapper\r\n    return self.execute(op_cls, *args, **kwds)\r\n  File \"/usr/lib/python2.7/site-packages/ncclient/manager.py\", line 232, in execute\r\n    raise_mode=self._raise_mode).request(*args, **kwds)\r\n  File \"/usr/lib/python2.7/site-packages/ncclient/operations/lock.py\", line 35, in request\r\n    return self._request(node)\r\n  File \"/usr/lib/python2.7/site-packages/ncclient/operations/rpc.py\", line 343, in _request\r\n    raise TimeoutExpiredError('ncclient timed out while waiting for an rpc reply.')\r\nTimeoutExpiredError: ncclient timed out while waiting for an rpc reply.\r\n\r\nfatal: [10.0.249.251]: FAILED! => {\r\n    \"changed\": false, \r\n    \"invocation\": {\r\n        \"module_args\": {\r\n            \"allow_agent\": false, \r\n            \"datastore\": \"running\", \r\n            \"host\": \"10.0.249.251\", \r\n            \"hostkey_verify\": false, \r\n            \"look_for_keys\": false, \r\n            \"password\": \"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER\", \r\n            \"port\": 830, \r\n            \"save\": false, \r\n            \"src\": \"<config>\\n    <System xmlns=\\\"http://cisco.com/ns/yang/cisco-nx-os-device\\\">\\n        <fm-items>\\n            <bgp-items>\\n                <********St>enabled</********St>\\n            </bgp-items>\\n        </fm-items>\\n    </System>\\n</config>\", \r\n            \"username\": \"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER\", \r\n            \"xml\": null\r\n        }\r\n    }, \r\n    \"msg\": \"error editing configuration: ncclient timed out while waiting for an rpc reply.\"\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/368919438","html_url":"https://github.com/ansible/ansible/issues/36786#issuecomment-368919438","issue_url":"https://api.github.com/repos/ansible/ansible/issues/36786","id":368919438,"user":{"login":"ansibot","id":6585283,"avatar_url":"https://avatars0.githubusercontent.com/u/6585283?v=4","gravatar_id":"","url":"https://api.github.com/users/ansibot","html_url":"https://github.com/ansibot","followers_url":"https://api.github.com/users/ansibot/followers","following_url":"https://api.github.com/users/ansibot/following{/other_user}","gists_url":"https://api.github.com/users/ansibot/gists{/gist_id}","starred_url":"https://api.github.com/users/ansibot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansibot/subscriptions","organizations_url":"https://api.github.com/users/ansibot/orgs","repos_url":"https://api.github.com/users/ansibot/repos","events_url":"https://api.github.com/users/ansibot/events{/privacy}","received_events_url":"https://api.github.com/users/ansibot/received_events","type":"User","site_admin":false},"created_at":"2018-02-27T15:36:46Z","updated_at":"2018-02-27T15:36:46Z","author_association":"CONTRIBUTOR","body":"cc @ganeshrn @lpenz @userlerueda\n[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)\n<!--- boilerplate: notify --->"}}
{"actor":{"display_login":"ansibot"}}