In previous post, I have mentioned about some simple scripting of Python for Arista. But today we will take a bigger step to automation of network. We will mention about Ansible and its components such that playbook, inventory and using to Arista topologies. We will not touch details of Ansible here, our purpose is how to use it to build our automated environment by knowing less scripting language.
Ansible is package that have modules of many python scripting of multi vendor, like Arista, Cisco, Citrix,A10, Azur, AWS etc. You will create an host file that includes you environment devices and playbooks to send tasks them. Ansible simply takes variables by user and exevute proper scripts to devices and configure them. It does this by SSH or API. I always prefer API. In below topology, I will create VLAN,Interface VLAN, Assignment IP address and BGP which redistribute connected routes each other.
Ansible holds eos modules of Arista in it is module directory. Those modues consist of Python scripting for you. BGP,LINKAGG,VLAN,INTERFACE etc.. Here notes that Arista continue to develop its modules with Ansible so some modules are replaced eos_config module for workaround solution. In ansible, you choose random module, give its paramters. Thats it. But for Arista, there is eos_config that provides reading config file directly and send it to devices directly. This is under develop and actually I preferer not use to read directly config. Because in config file, you should configure the config as you are in CLI. But our purpose is not to use CLI anymore in automated environment.
In my lab environment, I have a Centos 7 server and two arista switches whose management IPs are in same subnet. Centos is ansible controller server which holds my host and playbook files to run.
Part 1:Hosts File
Below is host file that to use of playbook file. This is simply shows IP address and connection method to devices. See not CLI, it is API.
Part 2:Playbook YAML File
Now, play is starting with playbook. Playbook is a YAML file. In my playbook, first I stated to hosts as eos_switches which are my devices. My playbook, after this “hosts” will see “tasks” which will be run. This part is consist of “modules“. This tasks will check version, send banner, create vlan and assignment vlan to interface ethernet 1 for both switches with the aid of hosts:eos_switches.
Second part is running per devices with the aid of hosts:eos_switches and . Because, there is IP address assignment and bgp config here so because of that, configuration should be configured per switches.Else, same tasks will be run for both switches. In this part, as you see, I used eos_config.py module for BGP. Normally, we would prefer eos_bgp.py module but there is bug and this is why we prefer eos_config.py for sending BGP from bgp.cfg.
– hosts: eos_switches
– name: Gather Show Version Facts
– ‘show version’
– name: configure the login banner
###THIS IS MY LAB BANNER###
###FOR BGP ENVIRONMENT IN ARISTA###
– name: Create vlan
– name: configure interface
– name: Ensure Ethernet1 is a trunk port
– name: Set intvlan4091 IPv4 address for arista1
– name: Set loopback IPv4 address for arista1
– name: BGP config for arista1
– hosts: eos_switches
– name: Set eintvlan4091 IPv4 address for arista2
– name: Set loopback IPv4 address for arista2
– name: BGP config for arista2
Sample Config of Arista after Ansible Using
arista1#show running-config interfaces vlan 4091
ip address 192.168.0.1/30
arista1#show running-config interfaces ethernet 1
switchport trunk allowed vlan 4091
switchport mode trunk
arista1#show running-config | section bgp
router bgp 100
neighbor 192.168.0.2 remote-as 101
neighbor 192.168.0.2 maximum-routes 12000
As a result, Ansible will help you to automate your network not only network devices. With some practise and reading of documentation, you can understand the modules and its required parameters to create you configuration. At the end of it, you can put a web page in front of Ansible to get variables from user and run tasks on web page. I think CLI has come to end.