PyATS and Robot device loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2022 01:35 PM
Hi All,
I’m new to PyATS and trying to write a simple loop in Robot to loop through devices in the ‘testbed.yaml’ file and output data (like show run) into a file for each device where the file name includes the device, time and date - anyone ideas on how to do this?
thanks!!
- Labels:
-
Other DevNet Topics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 03:45 AM
(off-topic warning: doesn't answer the question but provides an alternative solution)
There are pyATS modules for Ansible. With my limited experience I would (and have done) loop through my inventory using Ansible Tower (AAP). I am not sure what 'Robot' is. With Ansible you manage an inventory (similar to the testbed in Genie) and you write 'plays' that loop through the inventory (optionally with filters). Your loop does housekeeping (open the output file), selection (determine whether it is a ios or nxos device), processing the command(s), writing the output. Finally you will close the files, having created an output file for each device. Hint: all your code and resources (including the inventory) is stored in a git project. AFAIK Cisco supports the the pyATS (and other Cisco device) module 'collections'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 10:56 AM
@krandrews Hopefully this helps, you could use this as a base and expand from it.
---Output as ${device}.txt---
*** Settings ***
Library pyats
*** Variables ***
testbed_file testbed.yaml
*** Test Cases ***
Output show run to file for each device
[Tags] Output show run to file
${test_bed} = Load Testbed ${testbed_file}
FOR ${device} IN ${test_bed.devices}
Connect to device ${device}
Execute command show run
Write command output to file ${device}.txt
END
Close Testbed ${test_bed}
