Site Search

【初心者向けAnsible】BGPクロスネットワークを自動構築!Ansibleで始めるネットワーク構築 Part1

Introduction

This article introduces the basic usage of Ansible, an automatic configuration tool. Finally, we will use Ansible to configure the BGP cross network.
There are other articles related to Open Networking, so please see the articles that interest you from the "List of articles" below.

What is Ansible?

それでは最初にAnsibleについてご紹介していきます。
Ansibleとは簡単にいうと「インフラ構成管理ツール」です。

サーバーへAnsibleをインストールし、管理対象に対しパッケージのインストールや設定ファイルの編集などを一括でかつ自動で行わせることが可能です。
Ansibleの大きな特徴は、管理対象サーバーに専用のエージェント(常駐プログラム)をインストールする必要がない「エージェントレス」である点です。これにより、導入の手間が少なく、すぐに自動化を始めることができます。

今回はその中でも、ネットワーク構築を自動化するツールとしての使用方法をご紹介してきます。

What is Ansible?

Automatic setting image diagram by Ansible

Ansibleによる自動化の仕組みと手順

Ansible works very simply. The user can automatically configure the management target by describing the "ideal state" of the management target in a playbook and executing it.

【procedure】
① User writes playbook
② Run the playbook on the Ansible host (server)
(3) Automatically set the management target according to the contents of the playbook

Ansible behavior

Figure 2: Ansible schematic diagram

 

Ansibleの理解を深めるため、主要な構成要素を下記にまとめました。

word meaning
Inventory ・A file that describes the address of the host to be operated and defines the management target
・The default file is /etc/ansible/hosts
Module ・Minimum unit of processing executed on the managed object
・General-purpose library that executes the processing specified in Tasks
Task(Tasks lists) ・Files listed in an array in the order in which specific processes are to be executed
Playbook - A file that defines the status of the remote host (details of processing to be executed)
・Multiple modules can be combined to operate the managed host
・Describe in yaml

Playbook content example

Ansible環境の構築と初期設定

Next, I will introduce the environment construction for using Ansible.
First, the environment required for Ansible to work is as follows.

〇 Ansible host (server) side
-Ansible 2.3 or newer
- Python 2.6 or newer
- SSH connection is possible

*Since the required version differs depending on the network OS to be managed, basically we recommend using the latest version.

The above is the required version for Cumulus.

Install Ansible on the server

This time we will install Ansible on Ubuntu. The procedure is below.

 $ sudo apt update
 $ sudo apt install software-properties-common
 $ sudo apt-add-repository --yes --update ppa:ansible/ansible
 $ sudo apt install ansible

Since the installation method is slightly different for each OS, if you are using an OS other than Ubuntu, please refer to the installation procedure from the Ansible homepage. (URL below)

https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html?extIdCarryOver=true&sc_cid=701f2000001OH7YAAW

Ansible connection confirmation

The above completes the environment settings. Next, we will perform an Ansible connection test.
The /etc/ansible directory is created by default when Ansible is installed.
Then add the address of the target host to the inventory (/etc/ansible/hosts).

Ansible connection confirmation

Pingによる接続確認

By executing the following command, ping will be performed from the server to all managed devices described in hosts. If the ping passes, the connection confirmation is complete.

$ ansible -i [inventory file name] all –m ping

Ping

ping execution image

This time, we prepare new hosts separately from the default inventory (/etc/ansible/hosts), specify it and execute.

Ansibleでネットワークを自動設定する実践

BGPクロスネットワーク構築の準備と概要

Finally, we will use Ansible to automatically configure the white Box switch and configure the BGP cross network. This time, prepare a config file in advance, copy each file to the target switch, and prepare a playbook to apply the settings.

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

Automatic configuration of white Box switches with Ansible

BGP cross network diagram

Ansible directory structure

Ansibleの基本的なディレクトリー構成と、各ファイルの内容は以下です。

┣━ hosts  #インベントリーファイル

┃━ setup.yaml  #Playbookファイル

┗━ bgp-unnumbered  #各ホストの設定ファイルディレクトリー
  ┃
  ┣━ AS7726-A  #AS7726-32X用設定ファイルディレクトリー
  ┃    ┣━daemons
  ┃    ┣━frr.conf
  ┃    ┗━interfaces
  ┃   
  ┣━ AS7726-B  #AS7726-32用設定ファイルディレクトリー
  ┃    ┣━daemons
  ┃    ┣━frr.conf
  ┃    ┗━interfaces
  ┃
  ┗━ AS7326-A  #AS7326-54X用設定ファイルディレクトリー
  ┃    ┣━daemons
  ┃    ┣━frr.conf
  ┃    ┗━interfaces
  ┃
  ┗━ AS7326-B  #AS7326-54X用設定ファイルディレクトリー
           ┣━daemons
           ┣━frr.conf
           ┗━interfaces

Prepare the configuration file as follows.

 

hosts

hosts

playbook

playbook

The following 5 tasks are executed

① Task to submit the interface configuration to the switch
② Task to enable bgp daemon
③ Task to input FRR configuration to switch
④ Issue the reload command of the interface configuration on the switch
⑤ Issue the frr config reload command on the switch

inventory_hostname is a predefined variable that points to the hostname written in hosts

Run playbooks with Ansible

Next, we will run the playbook described above.

playbook execution log

playbook execution log

When you check the switch, you can see that the settings have been reflected and the BGP session has been established.

BGP execution result (1)

BGP execution result (1)

Routes are also advertised normally.

BGP execution result (2)

BGP execution result (2)

You can also confirm that pings fly to the loopback of each switch from the advertised route.

ping result

ping result

This is the basic usage of Ansible. Next time, I would like to show you how to create a setting config with Ansible.

At the end

Macnica provides a service that remotely provides an environment where you can experience open networking and conduct tests and verifications.
This service allows us to verify the operability of network OSes and perform tests that combine network OSes from various manufacturers, white Box switches, and optical transceivers.

マクニカではオープンネットワーキングを実際に体験し、試験や検証をおこなえる環境をリモートで提供するサービスのご用意があります。  本サービスでは、ネットワークOSの操作性の検証、様々なメーカーのネットワークOSやホワイトボックススイッチ、光トランシーバーを組み合わせた試験をおこなえます。

Image of remote verification service

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.

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.

Aviz Networks

We are pioneers of SONiC, an open source network operating system, providing observability, configuration automation tools and support from a team of SONiC experts.

IP Infusion

As a market leader among open networking providers, we provide reliable network solutions to over 600 customers, including carriers, service providers, and data centers.

Inquiry/Document request

In charge of Macnica Edgecore Networks

Weekdays: 9:00-17:00