Professional Documents
Culture Documents
Network Automation Using Ansible For Cisco Routers Basic Configuration
Network Automation Using Ansible For Cisco Routers Basic Configuration
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
- 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.
Reference