use-case: Create a VPN on AWS to a Cisco CSR v1000 router, generate a sequence of commands based on AWS-generated values replacing tokens in a template, configure the router, then save the startup-config - all in a fully automated manner, from the developer's laptop.
What I've always done myself to configure a router from a set of commands I need to apply in order, is what I see on the web when I search for this question - I ssh into the router, then "config t", then I manually paste the commands. I don't want to have this manual cut-and-paste action - I want to run statements on either the router itself, or on my laptop, to apply the commands which are in a script to the router configuration - INSTEAD of having to cut and paste them.
I thought I'd list what I have figured out so far here as it's been surprisingly hard to find how to do even this much simply and in one place. The following assumptions apply:
- I have an ~/.ssh/config file which simplifies what I need to specify on the command line
- This supplies the user as ec2-user, and specifies the correct SSH key.
- I'm using the ssh-agent, which supplies the SSH key passphrase for me
- The router's FQDN for this example is csr01.mydomain.com
- The set of commands I want to run is in csr01-apply-config.cfg
- I want to upload this file to the router, then apply all commands in the file ideally in a single action, as this script may need to make changes which could temporarily disrupt connectivity
- I want to store all such apply files in flash:apply-configs directory
So here's what I have so far - just missing the one key step:
List files in flash: filesystem
# ssh csr01.mydomain.com dir flash:
List files in nvram: filesystem
# ssh csr01.mydomain.com dir nvram:
- Create a directory to hold uploaded configuration apply files
# ssh csr01.mydomain.com mkdir flash:apply-configs
- Upload the generated configuration apply file
# scp csr01-apply-config.cfg csr01.mydomain.com:flash:/apply-configs/csr01-apply-config.cfg
- Confirm uploaded file exists
# ssh csr01.mydomain.com dir flash:apply-configs
Apply commands
>>>>>>>>>> HOW CAN I RUN THE COMMANDS IN A FILE HERE <<<<<<<<<<
For example, something like:# run flash:/apply-configs/csr01-apply-config.cfg
It seems like this should be simple, but I can't seem to find any description on if this is possible and if so, what commands to use
Show running config
# ssh csr01.mydomain.com show run
- Write running config to memory
# ssh csr01.mydomain.com write mem
- Copy startup config back to laptop
# scp csr01.mydomain.com:nvram:startup-config csr01-startup-config-$(date +%Y%m%d-%H%M).cfg