Showing results for 
Search instead for 
Did you mean: 

PyATS and Robot device loop

Level 1
Level 1

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?



2 Replies 2

Level 1
Level 1

(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'.

Level 1
Level 1

@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
    Close Testbed    ${test_bed}