You are on page 1of 5

Network Automation using Ansible for Cisco

Routers Basic Configuration


Jonathan Wijaya

Telematics Laboratory, School of Electrical Engineering and Informatics,


Bandung Institute of Technology, e-mail: nathanjaya123@gmail.com

Abstract: Network programmability is a trend, protocols, like OpenFlow. However, the


enhanced and inspired by Software Defined “traditional” non-SDN legacy networks need to
Networks, that are based on scripting methods keep the pace and respond to dynamic network
and standard programming languages used for changes. Network automation is a solution for
controlling and monitoring of network operational expenses saving, improving not
elements. This paper is illustrating a method in only the time spent for configuring the network
configuring network devices by using devices, but also the efficiency of network
automation, reducing time for equipment maintenance through procedures that are easier
configuration and easier maintenance. It uses to follow and implement at large scale.
Ansible in Ubuntu environment as the
controller, and Cisco routers as the managed All major vendors, including Cisco, started
nodes. These methods represent the future of promoting the software configurability of
networks, allowing the management of an networks (e.g. Cisco DevNet concept that
increased number of devices in a unitary way. promotes the creation of an open source
community for network programmability [5]).
Keywords: Network, Automation, Ansible. All new automation implementations are based
on generic programing methods (python, java)
1. Introduction and standard interfaces (Secure Shell SSH or
even RESTful webservices).
The number of devices in a network and their
heterogeneous nature is steadily increasing. However, only the newer devices have support
The traditional methods used for network for the new programmatic methods, and this
equipment configuration are time consuming, paper addresses methods to automate legacy
taking into consideration also the vendor network elements.
specific know-how needed. The Software
Defined Networks (SDN) concept tries to The main objective of this paper is to
eliminate the vendor dependency via standard demonstrate the efficiency of the scripting in
configuring network devices. For that we have parts, usage of OpenSSH for transport (with
created an emulated network topology in Eve- other transports and pull modes as alternatives),
ng, having as main element an Ubuntu Desktop, and a language that is designed around
with the role of a network controlling element. auditability by humans–even those not familiar
We have controlled the network devices in a with the program.
programmatic way using Ansible, based on
Python. Ansible is appropriate for managing all
environments, from small setups with a handful
2. Network Automation using Ansible of instances to enterprise environments with
many thousands of instances.
At its core, network automation has the main
goal of simplifying the tasks involved in Ansible manages machines in an agent-less
configuring, managing and operating network manner. There is never a question of how to
equipment, network topologies, network upgrade remote daemons or the problem of not
services and network connectivity. In my being able to manage systems because daemons
experimental setup I have used the Eve-ng are uninstalled. Because OpenSSH is one of the
emulator which is a tool for building, designing most peer-reviewed open source components,
and testing networks, capable now also to security exposure is greatly reduced. Ansible is
connect to external networks and allowing decentralized–it relies on your existing OS
integration with virtual images. credentials to control access to remote
machines. If needed, Ansible can easily connect
A. Network Setup with Kerberos, LDAP, and other centralized
authentication management systems.
For the specific implementation, I have used an
Ubuntu Desktop which is running Ansible, The scripts incorporate some functionalities
allowing to connect to devices and automate like hostname changing, IP address
their configuration via ssh connections. configuration, and routing protocols. The
scripts can be used for almost all network
Ansible is an IT automation tool. It can devices regardless of the vendor that produces
configure systems, deploy software, and them.
orchestrate more advanced IT tasks such as
continuous deployments or zero downtime The topology contains a cloud (Net) which is
rolling updates. used to connect the Ubuntu Desktop device
which will run the Ansible and its automated
Ansible’s main goals are simplicity and ease- scripts for configuring network devices, a
of-use. It also has a strong focus on security and Switch (using Cisco vIOS) that is making the
reliability, featuring a minimum of moving
connection to 2 Routers that will be Packaging Tool (APT) in Ubuntu. The
automatically configured (Figure 2.1). following commands will configure the
Personal Package Archives (PPA), install
Ansible, and install the newest python version.
$ sudo apt update
$ sudo apt install software-
properties-common
$ sudo apt-add-repository
ppa:ansible/ansible
$ sudo apt update
$ sudo apt install ansible
$ sudo apt install python

Figure 2.1 Topology B. Ansible Automation Methods

The Ubuntu Desktop needs to be in the same There are 3 main file in the Ansible directory,
network as the devices that we want to hosts, ansible.cfg, and Ansible Playbook file.
automatically configure so it can obtain an IP The hosts file is the inventory file where we add
via a common DHCP or we can configure a our managed nodes to be controlled by Ansible.
static IP address. It also must be connected to Ansible.cfg is the actual configuration file used
Internet for downloading the necessary tools. to tweak Ansible parameters. Once the
installation is done, we need to add some nodes
The routers need to be configured first. What in the hosts file. In my case I add 2 IP addresses
needs to be configured are IP address of the which belong to interface fa0/0 of my 2 routers.
connected interface and SSH, so that the Here is the content of my hosts file:
controller (Ubuntu Desktop) can access the //hosts
[iosxr]
routers. 10.10.1.99
10.10.1.199

An Ansible controller (the main component that


I grouped the 2 hosts with a group name ‘iosxr’
manages the nodes), is supported on multiple
because they are Cisco routers using iosxr
flavors of Linux, but it cannot be installed on
operating system. Then after the hosts file, the
Windows. For managed nodes, since Ansible
other file is the Ansible Playbook. Ansible
uses SSH to communicate with managed nodes,
playbook contains the configuration we want to
the node must be able to be accessed from SSH.
push to the devices. The playbook file has ‘.yml’
Going back to controller machine installation,
file extension. In my case, the contents of my
Python 2 (2.6 or above) needs to be installed. In
playbook file are the routers’ username and
my case, I am using Ubuntu as my OS, hence
password, hostname configuration, IP address
my focus would be on working with Ansible
configurations, and OSPF configuration. Here
using Ubuntu as the underlying OS. A way of
is the content of my playbook file:
installing Ansible is to use the Advanced
//ansible-playbook
---

- name: config
hosts: all
connection: local
gather_facts: no
tasks:
- name: configure provider
set_fact:
provider:
username: cisco
password: cisco
- name: set hostname
ios_config:
provider: "{{provider}}" Figure 2.2 Ansible Playbook Result
lines: hostname
{{ inventory_hostname }}
- name: interface IP address Figure 2.2 above shows the result after I run the
ios_config:
provider: "{{provider}}" playbook file. The result shows that I
lines:
- ip address 192.168.1.10 successfully changed 4 configurations in the
255.255.255.0 target routers. Those 4 configurations are
- no shutdown
- full-duplex hostname, interface IP address, loopback IP
parents: interface
FastEthernet 1/0 address, and OSPF.
- name: loopback interface
ios_config:
provider: "{{provider}}" For my future work I plan to automate network
lines:
- ip address 1.1.1.1 devices using Ansible alongside NAPALM.
255.255.255.255 Network Automation and Programmability
- no shutdown
parents: interface Abstraction Layer with Multivendor support
Loopback0
- name: configure ospf network [9] is a Python library that implements a set of
ios_config: functions to interact with different router
provider: "{{provider}}"
lines: vendor devices using a unified API. The
- router-id 1.1.1.1
- network 192.168.1.10 heterogeneous vendors are integrated via
0.0.0.255 area 0 drivers, and NAPALM offers support for most
parents: router ospf 1
of the important vendors.

After making sure the files’ contents are correct,


3. Conclusions
what we need to do is just run the playbook file.
In my case, my playbook file’s name is
Configuring and monitoring any device via
‘test.yml’, so what I need to type is:
automation, independent of vendors is a goal
ansible-playbook test.yml
implementable not only on SDN devices, but
also on other networking solutions. In this
paper, I have demonstrated the importance of
automation in a network that are not aware of
OpenFlow SDN protocol.

I have demonstrated that using Ansible,


network engineers do not need to configure by
themselves each individual device, they just
need to create the proper infrastructure and by
implementing automation scripting. The
network controllability becomes easier and
changes can be faster deployed, maybe even
automatically, as response to events that take
place in the network. So the legacy network
elements becoming similar with SDNs.

Reference

1. Ansible for Network Automation, https://docs.


ansible.com/ansible/latest/network/index.html
2. Tischer R., Gooley J. 2016. Programming and
Automating Cisco Networks. Cisco Press.
3. Cisco ”DevNet” Open Source Dev Center -
https://developer.cisco.com/site/opensource/
4. NAPALM (Network Automation and Pro-
grammability Abstraction Layer with Multi-
vendor support) https://napalm.readthedocs.io/
en/latest/
5. Ansible for Network Automation Tutorial,
https://www.networkcomputing.com/networkin
g/

You might also like