Hi all,
I am fairly new with Juniper.junos but know Ansible well and what I am trying to do is a fairly simple thing but it does not seem to work for me.
# cat hosts.sc2firewalls
[srx550]
192.168.11.1
---
- name: Get device facts
hosts: srx550
roles:
- Juniper.junos
connection: local
gather_facts: no
tasks:
- name: checking NETCONF connectivity
wait_for: host={{ inventory_hostname }} port=22 timeout=10
- name: retrieve info from devices
junos_get_facts: host={{ inventory_hostname }} logfile=/home/$USER/juniper.log
register: junos
- name: version
debug: msg="{{ junos.facts.version }}"
--------------------------------------
But my run got hung and timed out.
< TASK: checking NETCONF connectivity >
-------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
<192.168.11.1> REMOTE_MODULE wait_for host=192.168.11.1 port=22 timeout=10
<192.168.11.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1408631193.16-76332173120789 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1408631193.16-76332173120789 && echo $HOME/.ansible/tmp/ansible-tmp-1408631193.16-76332173120789']
<192.168.11.1> PUT /tmp/tmpLZeowt TO /home/steven/.ansible/tmp/ansible-tmp-1408631193.16-76332173120789/wait_for
<192.168.11.1> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/steven/.ansible/tmp/ansible-tmp-1408631193.16-76332173120789/wait_for; rm -rf /home/steven/.ansible/tmp/ansible-tmp-1408631193.16-76332173120789/ >/dev/null 2>&1']
ok: [192.168.11.1] => {"changed": false, "elapsed": 0, "path": null, "port": 22, "search_regex": null, "state": "started"}
< TASK: retrieve info from devices >
----------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
<192.168.11.1> REMOTE_MODULE junos_get_facts host=192.168.11.1 logfile=/home/$USER/juniper.log
<192.168.11.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1408631193.28-62119542719751 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1408631193.28-62119542719751 && echo $HOME/.ansible/tmp/ansible-tmp-1408631193.28-62119542719751']
<192.168.11.1> PUT /tmp/tmpfoMjLs TO /home/steven/.ansible/tmp/ansible-tmp-1408631193.28-62119542719751/junos_get_facts
<192.168.11.1> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/steven/.ansible/tmp/ansible-tmp-1408631193.28-62119542719751/junos_get_facts; rm -rf /home/steven/.ansible/tmp/ansible-tmp-1408631193.28-62119542719751/ >/dev/null 2>&1']
failed: [192.168.11.1] => {"failed": true}
msg: unable to connect to
192.168.11.1: ConnectTimeoutError(192.168.11.1)
---
I checked my firewall and I could do netconf just fine.
Warning: Permanently added '192.168.11.1' (ECDSA) to the list of known hosts.
<!-- No zombies were killed during the creation of this user interface -->
<!-- user steven, class j-super-user -->
<hello>
<capabilities>
<capability>urn:ietf:params:xml:ns:netconf:base:1.0</capability>
<capability>urn:ietf:params:xml:ns:netconf:capability:candidate:1.0</capability>
<capability>urn:ietf:params:xml:ns:netconf:capability:confirmed-commit:1.0</capability>
<capability>urn:ietf:params:xml:ns:netconf:capability:validate:1.0</capability>
<capability>urn:ietf:params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file</capability>
</capabilities>
<session-id>5080</session-id>
</hello>
]]>]]>
----
I copied the /home/steven/.ansible/tmp/ansible-tmp-1408631193.28-62119542719751/junos_get_facts and ran it manually and then stopped it. Here was what I got.
File "/usr/lib/python2.7/pdb.py", line 1314, in main
pdb._runscript(mainpyfile)
File "/usr/lib/python2.7/pdb.py", line 1233, in _runscript
self.run(statement)
File "/usr/lib/python2.7/bdb.py", line 400, in run
exec cmd in globals, locals
File "<string>", line 1, in <module>
File "./junos_get_facts", line 85, in <module>
'''
File "./junos_get_facts", line 137, in main
dev.open()
File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 392, in open
device_params={'name': 'junos'})
File "/usr/local/lib/python2.7/dist-packages/ncclient/manager.py", line 96, in connect_ssh
session.connect(*args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/ncclient/transport/ssh.py", line 182, in connect
sock.connect(sa)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
KeyboardInterrupt
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /usr/lib/python2.7/socket.py(224)meth()
-> return getattr(self._sock,name)(*args)
------
Please tell me what could be the problem.
Thank you very much.
Steven.