napalm-automation / napalm-ios

Apache License 2.0
31 stars 40 forks source link

ios issue - can't determine file system #154

Closed sincerywaing closed 7 years ago

sincerywaing commented 7 years ago

Description of Issue/Question

when using ios for ansible, encounter below issue -

fatal: [router1]: FAILED! => {"changed": false, "failed": true, "msg": "cannot connect to device: An error occurred in dynamically determining remote file system: dir router1#\nrouter1#\nrouter1#"}

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

Setup

napalm-ios version

(Paste verbatim output from pip freeze | grep napalm-ios between quotes below)

napalm-ios==0.6.2 napalm-iosxr==0.4.8

IOS version

(Paste verbatim output from show version between quotes below)

c3900-universalk9-mz.SPA.151-4.M5.bin

Steps to Reproduce the Issue

Playbook

my user is priviledge 15 (tacacs), not sure why this happens

Python 2.7.12+ (default, Sep 17 2016, 12:08:02) [GCC 6.2.0 20160914] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import napalm_base import napalm_ios napalm_ios.version '0.6.2' netmiko.version u'1.4.0' my playbook

name: Test Inventory #The Task Name hosts: router1 #This will be in your ansible inventory file connection: local #Required gather_facts: no

tasks: #Begin Tasks

name: get facts from device #Task Name napalm_get_facts: #Call the napalm module, in this case napal_get_facts hostname: "{{ hostname }}" #This is a parameter and is derived from your ansible inventory file username: 'user1' #The username to ssh with dev_os: 'ios' #The hardware operating system password: 'pass1' #The line level password optional_args: {'secret': 'pass2'} filter: 'interfaces, bgp_neighbors' #The list of items you want to retrieve. The filter keyword is inclusive of what you want register: result #Ansible function for collecting output

name: print results #Task Name debug: msg= "{{ result }}" #Display the collected output

actually my user is already pri 15 so I don't think secret is needed.

same playbook work for junos.

Error Traceback

(Paste the complete traceback of the exception between quotes below)

sincerywaing commented 7 years ago

I believe this has been discussed before but I can't figure out if there is any workaround.

sincerywaing commented 7 years ago

command line error

dev=device.open() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/napalm_ios/ios.py", line 123, in open self.dest_file_system = self.device._autodetect_fs() File "/usr/local/lib/python2.7/dist-packages/netmiko/cisco_base_connection.py", line 149, in _autodetect_fs "system: {} {}".format(cmd, output)) ValueError: An error occurred in dynamically determining remote file system: dir router1# router1# router1# router1# router1# quit()

sincerywaing commented 7 years ago

if I specify dest_file_system = ios, it seems to work. but I can't filter any information -

PLAYBOOK: test.yaml **** 1 plays in test.yaml

PLAY [Test Inventory] **

TASK [get facts from device] *** task path: /home/shawn/ansible-workspace/test.yaml:7 Using module file /home/shawn/ansible-workspace/napalm-ansible/library/napalm_get_facts.py

ESTABLISH LOCAL CONNECTION FOR USER: shawn EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1496242124.91-218286040057887 `" && echo ansible-tmp-1496242124.91-218286040057887="` echo ~/.ansible/tmp/ansible-tmp-1496242124.91-218286040057887 `" ) && sleep 0' PUT /tmp/tmpVWFNh5 TO /home/shawn/.ansible/tmp/ansible-tmp-1496242124.91-218286040057887/napalm_get_facts.py EXEC /bin/sh -c 'chmod u+x /home/shawn/.ansible/tmp/ansible-tmp-1496242124.91-218286040057887/ /home/shawn/.ansible/tmp/ansible-tmp-1496242124.91-218286040057887/napalm_get_facts.py && sleep 0' EXEC /bin/sh -c '/usr/bin/python /home/shawn/.ansible/tmp/ansible-tmp-1496242124.91-218286040057887/napalm_get_facts.py; rm -rf "/home/shawn/.ansible/tmp/ansible-tmp-1496242124.91-218286040057887/" > /dev/null 2>&1 && sleep 0' fatal: [router1]: FAILED! => { "changed": false, "failed": true, "invocation": { "module_args": { "dev_os": "ios", "filter": [ "interfaces_ip" ], "hostname": "router1.rtl.apple.com", "ignore_notimplemented": false, "optional_args": { "dest_file_system": "ios" }, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "provider": null, "timeout": 60, "username": "user" }, "module_name": "napalm_get_facts" }, "msg": "[interfaces_ip] cannot retrieve device data: Unexpected response from the router" } to retry, use: --limit @/home/shawn/ansible-workspace/test.retry PLAY RECAP ********************************************************************* router1 : ok=0 changed=0 unreachable=0 failed=1
ktbyers commented 7 years ago

@sincerywaing What does dir on that router show?

Yes, you can disable the autodetect function by setting the dest_file_system, but you will need to set it to the correct value (if you need any of the NAPALM-IOS config operations).

sincerywaing commented 7 years ago

Thanks Kirk!

Here is the dir

router1#dir Directory of flash0:/

1  drw-           0  Nov 28 2016 11:16:52 +00:00  .Trashes
2  -rw-       16344  Jul 20 2010 19:43:18 +00:00  DOM.JS
3  -rw-        4096  Nov 28 2016 11:16:52 +00:00  ._.Trashes

<snip, total around 120 lines>

429 -rw- 3412 Jul 20 2010 19:43:18 +00:00 xml.template

1023946752 bytes total (592633856 bytes free)

And what should I manually set the dest_file_system for ios?

now my setting is 'dest_file_system':'ios'

sincerywaing commented 7 years ago

@ktbyers

even I specify dest_file_system to flash0:, still get error

fatal: [router1]: FAILED! => { "changed": false, "failed": true, "invocation": { "module_args": { "dev_os": "ios", "filter": [ "facts", "interfaces", "bgp_neighbors" ], "hostname": "router1", "ignore_notimplemented": false, "optional_args": { "dest_file_system": "flash0:" }, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "provider": null, "timeout": 60, "username": "euser" }, "module_name": "napalm_get_facts" }, "msg": "[interfaces] cannot retrieve device data: Search pattern never detected in send_command_expect: show\ interface\ Gigab" }

ktbyers commented 7 years ago

@sincerywaing Does it work if you do the following:

"optional_args": {
    "dest_file_system": "flash0:",
    "global_delay_factor": 2,
},

Try using a value of 2 and a value of 4 (for global_delay_factor)

sincerywaing commented 7 years ago

@ktbyers Thanks Kirk! making global_delay_factor = 4 did the trick!

The only thing I still have concern is bgp_neighbors filter, which always return empty.

I have bgp neighbors in specific vrfs but not in global, does this fuction only search bgp neighbor in global vrf?

ktbyers commented 7 years ago

Yes, current get_bgp_neighbors only supports 'global' VRF.

Someone needs to write the support to add support for other VRFs.

We have a PR outstanding to add IPv6 AFI support into get_bgp_neighbors, but still don't have support for other VRFs.