# junos\_command

**URL:** <https://forum.ansible.com/t/junos-command/24314>\
**Category:** Ansible Project\
**Created:** [April 25, 2017, 7:31pm UTC](https://forum.ansible.com/t/junos-command/24314 "2017-04-25T19:31:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vadud3](https://avatars.discourse-cdn.com/v4/letter/v/ecc23a/32.png) [@vadud3](https://forum.ansible.com/u/vadud3)\
**Post date:** [April 25, 2017, 7:31pm UTC](https://forum.ansible.com/t/junos-command/24314/1 "2017-04-25T19:31:13Z")

</div>

I am failing to make junos\_command work

2017-04-25 15:28:49,152 p=4058 u=user | PLAY [sdwan-routers] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
2017-04-25 15:28:49,171 p=4058 u=user | TASK [junos\_command] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
2017-04-25 15:28:49,572 p=4084 u=user | creating new control socket for host [router.example.net:830](http://router.example.net:830) as user None  
2017-04-25 15:28:49,572 p=4084 u=user | control socket path is /home/user/.ansible/pc/c08d46d021  
2017-04-25 15:28:49,572 p=4084 u=user | current working directory is /home/user/ansible/sdwan  
2017-04-25 15:28:49,572 p=4084 u=user | using connection plugin netconf  
2017-04-25 15:28:49,629 p=4084 u=user | network\_os is set to junos  
2017-04-25 15:28:49,629 p=4084 u=user | ssh connection done, stating ncclient  
2017-04-25 15:28:59,694 p=4084 u=user | failed to create control socket for host [router.example.net](http://router.example.net)  
2017-04-25 15:28:59,695 p=4084 u=user | Traceback (most recent call last):  
File “/usr/bin/ansible-connection”, line 298, in main  
server = Server(sf\_path, pc)  
File “/usr/bin/ansible-connection”, line 135, in **init**  
self.conn.\_connect()  
File “/usr/lib/python2.7/dist-packages/ansible/plugins/connection/netconf.py”, line 95, in \_connect  
device\_params={‘name’: self.\_network\_os}  
File “/usr/lib/python2.7/dist-packages/ncclient/manager.py”, line 149, in connect  
return connect\_ssh(\*args, \*\*kwds)  
File “/usr/lib/python2.7/dist-packages/ncclient/manager.py”, line 118, in connect\_ssh  
session.connect(\*args, \*\*kwds)  
File “/usr/lib/python2.7/dist-packages/ncclient/transport/ssh.py”, line 372, in connect  
raise SSHError(“Could not open socket to %s:%s” % (host, port))  
SSHError: Could not open socket to [router.example.net:830](http://router.example.net:830)

2017-04-25 15:29:19,598 p=4084 u=user | number of connection attempts exceeded, unable to connect to control socket  
2017-04-25 15:29:19,599 p=4084 u=user | persistent\_connect\_interval=1, persistent\_connect\_retries=30  
2017-04-25 15:29:19,625 p=4058 u=user | fatal: [[router.example.net](http://router.example.net)]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “unable to open shell. Please see: [https://docs.ansible.com/ansible/network\_debug\_troubleshooting.html#unable-to-open-shell](https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell)”, “rc”: 255}  
2017-04-25 15:29:19,626 p=4058 u=user | PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
2017-04-25 15:29:19,626 p=4058 u=user | [router.example.net](http://router.example.net) : ok=0 changed=0 unreachable=0 failed=1

I can only ssh to the router through a proxy host and the router does not have any port 830 open and I verified.

Please advise a workaround…

Thanks

---

<div class="post-metadata">

**Author:** ![Guz\_Mateusz\_ISP](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@Guz\_Mateusz\_ISP](https://forum.ansible.com/u/Guz_Mateusz_ISP)\
**Post date:** [April 25, 2017, 7:50pm UTC](https://forum.ansible.com/t/junos-command/24314/2 "2017-04-25T19:50:36Z")

</div>

I might be mistaken, but when dealing with network devices there should be something like:

connection: local

somewhere at the beginning of the playbook.

And the content of the playbook itself would be helpful here I think.

Please also check:  
[https://www.ansible.com/webinars-training/ansible-playbooks-using-network-modules](https://www.ansible.com/webinars-training/ansible-playbooks-using-network-modules)

**Od:** [ansible-project@googlegroups.com](mailto:ansible-project@googlegroups.com) [[mailto:ansible-project@googlegroups.com](mailto:ansible-project@googlegroups.com)] **W imieniu** Asif Iqbal  
**Wysłano:** 25 kwietnia 2017 21:31  
**Do:** Ansible Project [ansible-project@googlegroups.com](mailto:ansible-project@googlegroups.com)  
**Temat:** [ansible-project] junos\_command

---

<div class="post-metadata">

**Author:** ![psprygada](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@psprygada](https://forum.ansible.com/u/psprygada)\
**Post date:** [April 25, 2017, 8:34pm UTC](https://forum.ansible.com/t/junos-command/24314/3 "2017-04-25T20:34:36Z")

</div>

HI Asif, junos\_command requires netconf to be enabled on the remote device.

---

<div class="post-metadata">

**Author:** ![Rama\_Krishna](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@Rama\_Krishna](https://forum.ansible.com/u/Rama_Krishna)\
**Post date:** [May 6, 2017, 12:30am UTC](https://forum.ansible.com/t/junos-command/24314/4 "2017-05-06T00:30:48Z")

</div>

Based on the error message, authentication parameters are not passed properly to the module.

I see it’s using netconf; so i think you have used connection method right…

Cheers

---

<div class="post-metadata">

**Author:** ![Gennadiy\_Krokodilov](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@Gennadiy\_Krokodilov](https://forum.ansible.com/u/Gennadiy_Krokodilov)\
**Post date:** [February 8, 2018, 10:30pm UTC](https://forum.ansible.com/t/junos-command/24314/5 "2018-02-08T22:30:01Z")

</div>

Boker Tov Asaf, did you managed to solve it?

I have exactly the same problem with ex4200 and Ansible 2.3.3. netconf is enabled on port 830 and accessible:

> **[playbooks]# ssh -s -p 830 ansible@juniper\_12 netconf**
> 
> **Welcome to Juniper ex4300-48t**
> 
> **Password:**
> 
> **urn:ietf:params:netconf:base:1.0**
> 
> **urn:ietf:params:netconf:capability:candidate:1.0**
> 
> **urn:ietf:params:netconf:capability:confirmed-commit:1.0**
> 
> **urn:ietf:params:netconf:capability:validate:1.0**
> 
> **urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file**
> 
> **urn:ietf:params:xml:ns:netconf:base:1.0**
> 
> **urn:ietf:params:xml:ns:netconf:capability:candidate:1.0**
> 
> **urn:ietf:params:xml:ns:netconf:capability:confirmed-commit:1.0**
> 
> **urn:ietf:params:xml:ns:netconf:capability:validate:1.0**
> 
> **urn:ietf:params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file**
> 
> **[http://xml.juniper.net/netconf/junos/1.0](http://xml.juniper.net/netconf/junos/1.0)**
> 
> **[http://xml.juniper.net/dmi/system/1.0](http://xml.juniper.net/dmi/system/1.0)**
> 
> **11528**
> 
> **]]\>]]\>**

This is debug log:

> **2018-02-09 01:13:25,964 p=17223 u=root | creating new control socket for host 192.168.89.240:830 as user ansible**  
> **2018-02-09 01:13:25,965 p=17223 u=root | control socket path is /root/.ansible/pc/1007ccc67b**  
> **2018-02-09 01:13:25,965 p=17223 u=root | current working directory is /etc/ansible/playbooks**  
> **2018-02-09 01:13:25,966 p=17223 u=root | using connection plugin netconf**  
> **2018-02-09 01:13:25,968 p=17223 u=root | failed to create control socket for host 192.168.89.240**  
> **2018-02-09 01:13:25,969 p=17223 u=root | Traceback (most recent call last):**  
> **File “/opt/ansible/bin/ansible-connection”, line 298, in main**  
> **server = Server(sf\_path, pc)**  
> **File “/opt/ansible/bin/ansible-connection”, line 134, in init**  
> **self.conn = connection\_loader.get(play\_context.connection, play\_context, sys.stdin)**  
> **File “/opt/ansible/lib/ansible/plugins/init.py”, line 358, in get**  
> **self.\_module\_cache[path] = self.\_load\_module\_source(name, path)**  
> **File “/opt/ansible/lib/ansible/plugins/init.py”, line 343, in \_load\_module\_source**  
> **module = imp.load\_source(full\_name, path, module\_file)**  
> **File “/opt/ansible/lib/ansible/plugins/connection/netconf.py”, line 39, in**   
> **raise AnsibleError(“ncclient is not installed”)**  
> **AnsibleError: ncclient is not installed**

If you realised how to fix it, please share.  
Thanks!

---

<div class="post-metadata">

**Author:** ![ganeshrn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ganeshrn/32/1021_2.png) [@ganeshrn](https://forum.ansible.com/u/ganeshrn)\
**Post date:** [February 9, 2018, 5:17am UTC](https://forum.ansible.com/t/junos-command/24314/6 "2018-02-09T05:17:49Z")

</div>

> **AnsibleError: ncclient is not installed**

Please install ncclient and retry.

Command to install ncclient using pip:

# pip install ncclient

Regards,  
Ganesh

---

<div class="post-metadata">

**Author:** ![Gennadiy\_Krokodilov](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@Gennadiy\_Krokodilov](https://forum.ansible.com/u/Gennadiy_Krokodilov)\
**Post date:** [February 10, 2018, 5:48pm UTC](https://forum.ansible.com/t/junos-command/24314/7 "2018-02-10T17:48:27Z")

</div>

Hi Ganesh,  
Thanks!  
I moved FWD and installed it from git, now it is listed in packages:

**[root@server]# pydoc modules | grep -i ncc**  
**UserDict datetime ncclient (package) sre\_parse**  
**[root@server]#**

but I still have same error, absolutely the same.

It looks to me as Ansible configuration issue.  
I don’t exactly know where to put ncclient module(path where Ansible looks for it) which I installed with setup.py.  
At the moment I just added its patch to env (so its listed by pydoc):

**ANSIBLE\_LIBRARY=/opt/ansible/lib/ansible/modules:/root/Ansible\_install/ncclient-0.4.2**

**ANSIBLE\_HOME=/opt/ansible**  
**PYTHONPATH=/opt/ansible/lib:/root/Ansible\_install/ncclient-0.4.2**

**[root@playbooks]# ansible --version**  
**7198 1518284728.95276: starting run**  
**ansible 2.3.3.0**  
**config file = /etc/ansible/ansible.cfg**  
**configured module search path = [u’/opt/ansible/lib/ansible/modules’, u’/root/Ansible\_install/ncclient-0.4.2’]**  
**python version = 2.6.8 (unknown, Nov 7 2012, 14:47:34) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]**  
**[root@playbooks]#**

I know, Im not cool by running this directly as root, but this is just test env.

Thanks.

---

<div class="post-metadata">

**Author:** ![Gennadiy\_Krokodilov](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@Gennadiy\_Krokodilov](https://forum.ansible.com/u/Gennadiy_Krokodilov)\
**Post date:** [February 10, 2018, 7:55pm UTC](https://forum.ansible.com/t/junos-command/24314/8 "2018-02-10T19:55:59Z")

</div>

OK, looks like I found the root cause:

**VIP\_CR:[root@upm1 playbooks]# python**  
**Python 2.6.8 (unknown, Nov 7 2012, 14:47:34)**  
**[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2**  
**Type “help”, “copyright”, “credits” or “license” for more information.**  
**\>\>\> from ncclient import manager**  
**Traceback (most recent call last):**  
**File “”, line 1, in**   
**File “build/bdist.linux-i686/egg/ncclient/manager.py”, line 22, in**   
**File “build/bdist.linux-i686/egg/ncclient/operations/init.py”, line 16, in**   
**File “build/bdist.linux-i686/egg/ncclient/operations/rpc.py”, line 18, in**   
**File “build/bdist.linux-i686/egg/ncclient/xml\_.py”, line 22, in**   
**ImportError: /usr/lib/libexslt.so.0: symbol gcry\_cipher\_setkey, version GCRYPT\_1.2 not defined in file libgcrypt.so.11 with link time reference**  
**\>\>\>**

ncclient needs to resolve dependencies.

---

<div class="post-metadata">

**Author:** ![Gennadiy\_Krokodilov](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@Gennadiy\_Krokodilov](https://forum.ansible.com/u/Gennadiy_Krokodilov)\
**Post date:** [February 10, 2018, 11:33pm UTC](https://forum.ansible.com/t/junos-command/24314/9 "2018-02-10T23:33:36Z")

</div>

OK, Finally I got ncclient installed and it works fine (all dependencies solved),  
But this is what confusing me now:

**2018-02-11 02:01:07,225 p=17431 u=root | ssh connection done, stating ncclient**  
**2018-02-11 02:01:09,832 p=17431 u=root | ncclient manager object created successfully**  
**2018-02-11 02:01:09,833 p=17431 u=root | connection established to 192.168.89.240 in 0:00:02.721349**  
**2018-02-11 02:01:10,108 p=17431 u=root | incoming request accepted on persistent socket**  
**2018-02-11 02:01:10,109 p=17431 u=root | socket operation is CONTEXT**  
**2018-02-11 02:01:10,111 p=17431 u=root | socket operation is EXEC**  
**2018-02-11 02:01:10,112 p=17431 u=root | socket operation completed with rc 0**  
**2018-02-11 02:01:10,143 p=16797 u=root | open\_session() returned 0 ok**  
**2018-02-11 02:01:10,577 p=16797 u=root | Using module file /opt/ansible-2.3.3.0/lib/ansible/modules/network/junos/junos\_command.py**  
**2018-02-11 02:01:10,713 p=16797 u=root | The full traceback is:**  
**Traceback (most recent call last):**  
**File “/tmp/ansible\_iVnNY8/ansible\_module\_junos\_command.py”, line 164, in ?**  
**from functools import partial**  
**ImportError: No module named functools**

**2018-02-11 02:01:10,714 p=16797 u=root | fatal: [hsbu12]: FAILED! =\> {**  
**“changed”: false,**  
**“failed”: true,**

This module is installed and listed but, **junos\_command.py** can’t find it.  
Does anybody have any ideas?

Thanks in advance!
