How to automatically configure white Box switches using Ansible for beginners part 2

Introduction

In the previous article, I introduced that Ansible is a "tool for automating network construction" and showed that it is possible to automatically build a BGP cross-network by using a pre-prepared configuration file. This time, I would like to introduce a place where the configuration file can also be automatically generated using Ansible.

There are other articles related to Open Networking, so please see the articles that interest you from the "List of articles" below.

Advantages of creating configuration files with Ansible

For those of you reading this article, you might be wondering if you don't have to go through the trouble of creating a configuration file using Ansible and just create it manually. I think there are some people who think so.

It's certainly fine if it's a configuration file for a few switches, but if you have a large network with dozens or more switches, it becomes a very time-consuming task. There is also a high possibility that mistakes will occur.

However, looking at the contents of the configuration file, there are no major differences between the switches, only some parameters are different.
In exactly such situations, by using Ansible's template module, you can easily create configuration files for dozens of switches, and you can easily expand the configuration in the future. It also greatly reduces the chance of typos.

In summary, there are three points below.

3 benefits of using Ansible

3 benefits of using Ansible

This benefit applies not only to the template module, but also to Ansible itself. Ansible is a very powerful tool that greatly reduces user load.

What is Ansible's template module?

First of all, what is a template module? I would like to talk about this.

The template module is a module that can use the template engine for python called Jinja2. This makes it possible to automatically create dozens of configuration files without much effort.

Specifically, Jinja2's template file allows you to use control statements such as for statements and if statements in combination with variables, and it is possible to create a configuration file with parameters changed for each switch all at once.

Now, I would like to actually put it into operation and show you how it works.

Automatic creation of configuration files with Ansible

Now let's actually create a configuration file using Ansible. This time, we will create a startup-config that can configure a BGP cross network with OcNOS. After applying the settings, the network created will be exactly the same as the configuration created in the previous article.

environment
·server
-Ubuntu 16.04
 
・White Box switch
-Edgecore: AS7726-32X x 2 & AS7326-56X x 2

・NOS
-OcNOS 1.3.9

BGP cross network diagram

BGP cross network diagram

Ansible directory structure

├── hosts # inventory file

├── make_conf.yaml #Playbook file

└── roles

├── Leaf
│ │
│ ├── tasks
│ │ └── main.yml #task to create leaf config
│ │
│ ├── templates
│ │ └── leaf.j2 #Jinja2 template file for leaf
│ │
│ └── vars
│ └── main.yml stores #leaf switch variables

└── spine

├── tasks
│ └── main.yml # task to create spine config

├── templates
│ └── spine.j2 #Jinja2 template file for spine

└── vars
└── main.yml stores #leaf switch variables

Set the configuration file (hosts, playbook) as follows.

*The configuration files to be introduced from now on can be downloaded by answering the questionnaire on the document download form at the end of this article.

 

hosts

hosts

Playbook

Playbook

Next is the contents of spine in the roles directory

spine/tasks/main.yml

spine/tasks/main.yml

The above is a task that creates a configuration file using the template module and copies it to the /tmp/confgs directory.

spine/templates/spine.j2

spine/templates/spine.j2

By using if and for statements in Jinja2 template files, it is possible to create configuration files with different parameters for each switch.

In the figure above, variables are in red, and if and for statements are in blue.

spine/vars/main.yml

spine/vars/main.yml

A file containing variables used in templates.

The leaf in the roles directory is almost the same as spine, so I will omit it.

Run playbooks with Ansible

Next, we will run the playbook described above.

Playbook execution screen

Playbook execution screen

I can confirm that it runs correctly and that four configuration files are created.

4 configuration files created

4 configuration files created

Next, apply the created file to each switch.

(Although I will not introduce it in this article, it is of course possible to set OcNOS using Ansible to automatically enter a white Box.)

After applying the settings, you can see that the BGP session is successfully established.

BGP results

BGP results

In addition, the route is also advertised, and it can be confirmed that pings can be sent to the loopback of each switch.

BGP ping execution result

BGP ping execution result

The above is how to automatically create a configuration file using Ansible.

This is the end of the article introducing "tools for automating network construction" using Ansible. Next time, I will introduce ZTP, which automates the switch construction stage.

Document download form

The configuration file used in this article can be downloaded from the URL provided in the document download guide email by answering the questionnaire from "Click here to download the document" below.

At the end

Macnica provides a service that remotely provides an environment where you can experience open networking and conduct tests and verifications.

With this service, you can verify the operability of the network OS and perform tests that combine network OSes from various manufacturers, white Box switches, and optical transceivers.

Remote verification service image diagram

Remote verification service image diagram

It is a service that allows you to easily verify open networking, and the basic configuration is free of charge.

You can check the downloadable materials for available network OS and white Box switches, specific use cases, and how to apply. The materials can be downloaded from the URL listed in the information email by answering the questionnaire from the "Macnica Network OS Remote Verification Service" below.

These people are using the remote verification service.

These people are using the remote verification service.

Here are some testimonials from people who have actually used the service.

 

Furukawa Network Solution Co., Ltd.

“Recently, the number of remote service environments is increasing, but I was impressed with the ease of access to the evaluation equipment.

The materials you provided were easy to understand, and we were able to proceed smoothly with the intended verification. ”


Click here for list of materials

Document list

In addition to introducing products handled by Macnica,
We publish materials related to open networking, such as BGP cross network automatic construction files and network operation test evaluation reports.

Click here for details

Product Page Top

Edgecore Networks

We continue to be a pioneer in open networking by developing and selling products related to OpenNetworking/white Box switches.

DELTA ELECTRONICS

We have many achievements in supporting the business of major OEM customers in Japan and overseas, and provide high-quality/high-reliability network products.

CGS Tower Networks

We provide a network packet broker (NPB) that utilizes state-of-the-art general-purpose hardware.

Inquiry

If you have any questions regarding this article, please contact us below.

Macnica
In charge of OpenNetwork

Contact us by phone:
045-470-9831