ansible is unable to connect to junos device

481 views
Skip to first unread message

fatimazahr...@gmail.com

unread,
Apr 20, 2017, 7:31:09 AM4/20/17
to Junos Python EZ
Hi all, 
I'm new to ansible, and I need to backup a junos device configuration, I tried the solution bellow


#### host 
aa.bb.cc.dd


#####playbook
---
- name: Get configuration
  hosts: all
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos
  tasks:
    - name: Getting config ... please wait
      junos_get_config:
        host={{ inventory_hostname }}
        user=XXXX
        passwd=xxxx
        dest=etc/ansible/Backups/{{ inventory_hostname }}.conf
        logfile=/tmp/changes.log
 

After running the playbook, i get the following error:

PLAY [Get configuration] *******************************************************

TASK [Getting config ... please wait] ******************************************
fatal: [aa.bb.cc.dd]: FAILED! => {"changed": false, "failed": true, "msg": "unable to connect to aa.bb.cc.dd: ConnectTimeoutError(1aa.bb.cc.dd)"}
to retry, use: --limit @/etc/ansible/playbooks/test.retr

PLAY RECAP *********************************************************************
aa.bb.cc.dd                 : ok=0    changed=0    unreachable=0    failed=1



How Can I solve this problem ?

Stacy Smith

unread,
Apr 20, 2017, 10:54:51 AM4/20/17
to Junos Python EZ
Your playbook looks correct. 

Is NETCONF configured on your device with:
set system services netconf ssh

If so, can you confirm that you can reach the device from the Ansible host on the default NETCONF port of 830:
ssh -s -p830 username@hostname netconf

Some Junos platforms to do not listen for NETCONF on port 830. On those platforms you must connect on port 22. If the above test on port 830 fails, try:
ssh -s -p22 username@hostname netconf

If that test succeeds, you can add "port=22" as an additional argument to the junos_get_config module in your playbook.

--Stacy

fatimazahr...@gmail.com

unread,
Apr 20, 2017, 11:27:03 AM4/20/17
to Junos Python EZ
Thank you Stacy, I tried port 22, and  that resolves the problem, but unfortunately I got the following error:

PLAY [Get configuration] *******************************************************

TASK [Getting config ... please wait] ******************************************
fatal: [aa.bb.cc.dd]: FAILED! => {"changed": false, "failed": true, "msg": "Uncaught exception - please report: [Errno 2] No such file or directory: 'etc/ansible/Backups/aa.bb.cc.dd.conf'"}
        to retry, use: --limit @/etc/ansible/playbooks/test.retry

PLAY RECAP *********************************************************************
aa.bb.cc.dd                 : ok=0    changed=0    unreachable=0    failed=1   


I don't know why  I have this error even if the Backups directory exists :(

Stacy W. Smith

unread,
Apr 20, 2017, 11:33:43 AM4/20/17
to fatimazahr...@gmail.com, Junos Python EZ
On Apr 20, 2017, at 9:27 AM, fatimazahr...@gmail.com wrote:
> TASK [Getting config ... please wait] ******************************************
> fatal: [aa.bb.cc.dd]: FAILED! => {"changed": false, "failed": true, "msg": "Uncaught exception - please report: [Errno 2] No such file or directory: 'etc/ansible/Backups/aa.bb.cc.dd.conf'"}
> to retry, use: --limit @/etc/ansible/playbooks/test.retry
>
> I don't know why I have this error even if the Backups directory exists :(


In your playbook you have:
dest=etc/ansible/Backups/{{ inventory_hostname }}.conf

Because the path doesn't start with a /, it's relative to the playbook directory. I expect you meant for this to be an absolute path, so change it to:
dest=/etc/ansible/Backups/{{ inventory_hostname }}.conf

You also need to make sure that the /etc/ansible/Backups path exists and is writeable by the user running the playbook.

--Stacy

fatimazahr...@gmail.com

unread,
Apr 20, 2017, 11:43:13 AM4/20/17
to Junos Python EZ, fatimazahr...@gmail.com
Thank you very much, That helps me a LOT :)
Reply all
Reply to author
Forward
0 new messages