Using Python to Automate Network Administration Task

So I rolled into work, grabbed my second cup of coffee for the day and sat down at my desk. I had to make some network config changes, but I had put off applying the changes. I knew I was going to be updating a few devices and I’m always hesitant to make changes to working systems. Of course, I wanted to save the running configs for each device before making changes. But it’s also so tedious to connect to each device to make backups. Honestly, I skip it sometimes. I shouldn’t even be admitting that.

As a network administrator who is responsible for several different devices, such as switches and routers, you have a lot of regular tasks you should do. Being a responsible administrator means that you should have backups of your configurations. You should make sure you know how to update configurations. And you should do these things very regularly.

These tasks are probably equally important and tedious. They are manual and boring tasks. Nobody wants to do them. In fact, we often get a little behind and don’t back things up frequently because it’s a hassle.

Well prepare your goodbyes to the tedium. The company may not have given you a sidekick to whom you can delegate the boring work, but there are solutions. You can simplify and automate these tasks and hand them off to your Python program. We’re going to have some fun here and create a program that will be your own personal sidekick. We’ll teach is how to do the dull work. And then we’re going to enjoy watching is do the work for us while we sit around contemplating the facility of IPv6 and whether 3D printers will one day evolve into Star Trek style transporters.

Taking the time to work through this tutorial is going to level up your career in several ways:

  1. As a network administrator because you are being responsible and caring for your entire network including the possibilities of disasters.
  2. As a part of a larger team because you are becoming an efficiency expert by automating tasks.
  3. As an IT professional because you are expanding your skills by adding some basic programming techniques into your toolbelt.
  4. As a human being because you’re going to have some fun handing off these mundane tasks to a computer. It’s immensely gratifying to know that you’ve got things handled and it’s all automatic. Ain’t nothing better than having a computer do your work while you sleep!

So, let’s get started with an initial project.

We’re going to build up to a working command-line program that you can run to create backup config files for all of the devices on your network. The program, your sidekick, is going to go through its list of devices, connect to each one by SSH, and save a copy of the config to your local drive. Then you’ll know that if anything happens to any of your devices you will have be able to turn on a new device, push your config backup, and be back in business.

What You Will Need for the Tutorial

  • Python 3+ interpreter.
  • Internet connection. This is really only need to install an SSH library for Python. You will, of course, need some network connection to talk to your devices.
  • A Cisco network device (such as a firewall) to which you can connect and safely execute some commands.
  • A text editor so you can write some Python code.
  • A Terminal window (a command prompt where you can run, well, commands).