HiRoLabブログ

HiRoのゆるふわIT備忘録

VMware ExploreでVMUGボランティアに参加した話

はじめに

2022/11/15-16に開催されたVMware Explore 2022 Japanにて
VMUGブースのボランティアスタッフとして参加した感想を簡単にツラツラと・・・

目次

対象者

本ブログを読み進めるにあたり対象者はこちら

・VMUGやvExpertに興味がある人

・私同様、これからvExpertを目指そうとしている人

参加前の思い

ボランティア参加前の思いや目的を簡単に

・過去のVMware Explore(VMworld)オフラインの話など聞き、次こそは!!!

・普段のオフライン/オンラインのVMUGイベントだけは経験できないことが出来ると思ったから

・学生時代に某ITイベント(展示会)のボランティアを行い楽しかった経験もあり、
またどこかでボランティア経験をしたいと思っていたから

・今後のvExpert取得の活動に繋げたい

実際に参加して

ボランティアの内容はブース訪問者にVMUGの活動を簡単に紹介して、VMUGメンバーへの登録の紹介など行っていくもので
実際、私が案内した何人かVMUGメンバーに登録いただいたこともあり、ボランティア活動のお仕事が楽しいものになった

また、イベント全体を通して今後のエンジニアとして活動していく上でのモチベーション向上にも繋がった

このような感じのブースでVMUGの紹介とノベルティ配布をしました

本イベント後に懇親会もあり普段お話できない方と色々なご意見を聞くことができとても有意義であった (懇親会の写真は撮れてない。。。m(__)m)

最後に

本イベントと懇親会を通して普段では経験できないことを経験できた またモチベーションの向上にも繋がったので
また、今後はこのような経験をベースにvExpertの取得に向けて取り組んでいきたい

zabbix 6.0を構築してみた

はじめに

Zabbixの構築ブログを掲載していなく、せっかくなので6.0で構築してみた インストール時のエラーなど、初心者がハマる点についの備忘録しての記事になる

目次

対象者

・ESX上の仮想マシンにてZabbixを構築し、ネットワーク監視を行いたい人

環境

ESXiのバージョンは6.7

ESXi以外の環境は環境は下図を参考

zabbix インストール

下記インストールマニュアル通りに順に実行

www.zabbix.com

zabbixリポジトリインストール

# wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4%2Bubuntu20.04_all.deb
# dpkg -i zabbix-release_6.0-4+ubuntu20.04_all.deb
# apt update

apt updateを実施した際、下記のようなメッセージが発生

N: リポジトリ 'https://repo.zabbix.com/zabbix/6.0/ubuntu focal InRelease' がアーキテクチャ 'i386' をサポートしないため設定ファイル 'main/binary-i386/Packages' の取得をスキップ

解決策 /etc/apt/sources.list.d/zabbix.listを編集

deb https~とあるのでdebhttpsの間に[arch=amd64]を追加して再度apt updateを行うと解消される

本メッセージを解消せずに先進めるとパッケージインストールの際エラーが発生する
エラーの内容は次の工程を参照

必要なパッケージ類のインストール

マニュアル通り下記コマンドを実行

apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent

リポジトリインストール時にも記述した通り、パッケージ取得がskipされることにより下記のエラーが発生する為、前工程でのskipは解消する必要がある

E: パッケージ zabbix-apache-conf が見つかりません
E: パッケージ zabbix-sql-scripts が見つかりません

データベースの構築

マニュアル通り実行する前に書きに注意

マニュアルには記載がないですが、mysql-serverを入れてないとsocketファイルが見つからないエラーになる為、下記コマンドにて事前にインストールをしておくこと

apt install mysql-server

ここからデータベースの構築を開始

mysql -u root -p
パスワードはroot のパスワードを入力

mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.01 sec)

mysql> create user zabbix@localhost identified by 'ユーザのパスワード入力';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;

mysqlのユーザ(zabbix)のパスワードは任意で設定すること

スキーマとデータをインポート

マニュアル通り下記を実行

zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

confファイルにパスワード設定

マニュアル通り/etc/zabbix/zabbix_server.confをエディタで開き、DBPasswordがコメントアウトされている為、 コメントを外して、データベース構築でユーザー(zabbix)に設定したパスワードを登録

DBPassword=<ユーザ(zabbix)のパスワード>

サービスの再起動と有効化

マニュアル通り下記を実行

# systemctl restart zabbix-server zabbix-agent apache2
# systemctl enable zabbix-server zabbix-agent apache2

マニュアルには記述がないが、正しくサービスが稼働してるかの確認は下記コマンドにて確認

systemctl status zabbix-server
systemctl status zabbix-agent 
systemctl status apache2

webアクセスにて初期設定

アクセス先はhttp://<ホストIP>/zabbix

言語設定

前提条件確認

内容を確認して次へ

データベースへ接続

データベース構築で設定したユーザー(zabbix)のパスワードを入力したら次へ

サーバ名とタイムゾーン設定

zabbixサーバ名とタイムゾーンを設定

上記までで設定は完了 デフォルトの書きユーザ名とパスワードで
ユーザ名:Admin
パスワード:zabbix

下図のような画面が表示されればZabbixの構築は完了

おわりに

Zabbixでのホスト登録は過去の記事にZabbix 5.0バージョンで検証してるものになるが、参考程度に拝見いただければ幸いです
また、Ansibleを使ったホスト登録の自動化などの記事もある

VMware ESXiにvSRXを構築する方法

はじめに

VMware ESXiに仮想マシンとして、JuniperのvSRXを構築する方法の備忘録となります

目次

対象となる人

・Juniperのネットワーク製品であるSRXをESXiの仮想マシン環境として遊びたい人
・vSRXだけでなくCSR1000vといった他ベンダーの製品と接続してみたい人
VMware ESXiやネットワークの両方に興味がある人

検証環境と手順の概要

検証環境
VMware ESXi on PowerEdge R610 ※ESXiは無償版を使用

手順の概要
ESXi環境にvSRXのOVAファイルを展開して仮想マシンとして構築

次からの手順を参考に構築

ovaファイルダウンロード

ovaファイルのダウンロードにはJuniperのアカウントが必要となる

ovaファイルはこちらからダウンロード

今回は下記のovaファイルをダウンロード

f:id:HiRo1325:20220415205555p:plain

ESXiの設定とエラーの対処

仮想マシンを新規作成(OVAファイルから仮想マシンをデプロイを選択) f:id:HiRo1325:20220416003322p:plain

ovaファイルの指定と仮想マシン名入力 f:id:HiRo1325:20220416003516p:plain

ストレージの選択 f:id:HiRo1325:20220416003607p:plain

使用許諾契約に同意して次へ f:id:HiRo1325:20220415211120p:plain

デプロイオプションの設定 f:id:HiRo1325:20220415211250p:plain

エラー f:id:HiRo1325:20220415211348p:plain

エラーを調べてみたところ、下記の記事で同件の事象が見つかった https://gbe0.com/posts/networking/juniper/juniper-vsrx-deployment-on-esxi-6-7-error/

vSRXのバージョン=18.2R1からあるエラーのようだ
ovftoolを使うと構築可能

ovftoolを使って構築

ovftoolはこちらからダウンロードを行う。

ovftoolを使った構築はこちら

f:id:HiRo1325:20220415222211p:plain

ovftoolが格納されているフォルダにコマンドプロンプトにて移動し図の通りovftoolコマンドを実行
ovftoolのパラメーター(赤文字)は、個人の環境に合わせる必要がある為、構築する際は赤文字箇所に注意

ovftool -dm=thick -ds=datastore1 -n=仮想マシンの名前 --net:"VM Network"="VM Network" "ovaファイルのパス" vi://root@ESXi-IPアドレス

起動

パワーオンにて起動 f:id:HiRo1325:20220415213928p:plain

rootでログインが可能 f:id:HiRo1325:20220415213748p:plain

終わりに

今回vSRXを構築までとする

過去の記事にCSR1000vを構築したので、今後はvSRXとCSR1000v間でルーティングプロトコルをしゃべらせる
またAnsibleにてconfigの自動化も試す予定

日が空くと思われるが、逐一VMware ESXiの仮想マシンを使った検証記事を掲載予定

Netbox/Ansibleを使ってzabbixのデバイス登録自動化

はじめに

ubuntu上にdockerコンテナにてNebox環境を構築
ansible,その他必要なパッケージのインストールを行いzabbixのデバイス登録の自動化を行った。

動作環境

  1. OS
    ubuntu on ESXi

  2. Netbox Netbox on docker

  3. Ansibleバージョン

ansible            5.1.0    
ansible-core       2.12.1 
  1. zabbix

hiro1325.hatenablog.com

zabbixの環境は前回の記事と同等のものを使用

目次

その他必要なパッケージ

pynetbox
netaddr
zabbix-api

Netboxの設定

下図にあるcisco1という名前のデバイスをzabbixに登録を行う。

f:id:HiRo1325:20220113023054p:plain

zabbixの事前確認

下図にcisco1という名前のデバイスが登録されていないことを確認。

f:id:HiRo1325:20220113023434p:plain

cisco側にSNMP等の設定を行っていない為、今回はzabbixの登録までとなる。

インベントリファイル

[zabbix]
192.168.100.14

Ansible-playbooks

---
- hosts: zabbix
  #  gather_facts: False
  user: root
  connection: local
  vars:
    - netbox_url: http://localhost:8000
    - netbox_token: 0123456789abcdef0123456789abcdef01234567
  tasks:
    - name: create host 
      local_action:
        module: community.zabbix.zabbix_host
        server_url: http://192.168.100.14/zabbix
        login_user: Admin
        login_password: zabbix
        host_name: "{{ query('netbox.netbox.nb_lookup', 'devices',api_filter='manufacture=cisco',
                        api_endpoint=netbox_url, token=netbox_token)[0].value.name }}"
        visible_name: "{{ query('netbox.netbox.nb_lookup', 'devices',api_filter='manufacture=cisco',
                        api_endpoint=netbox_url, token=netbox_token)[0].value.name }}"
        description: hostmake
        host_groups: cisco_router
        link_templates: Template Net Cisco IOS SNMPv2
        status: enabled
        state: present
        inventory_mode: disabled
        ipmi_authtype: null 
        ipmi_privilege: 2
        interfaces:
          - bulk: 1
            details:
                community: '{$SNMP_COMMUNITY}'
            type: '2'
            main: 1
            useip: 1
            ip: "{{ query('netbox.netbox.nb_lookup', 'ip-addresses',api_filter='device=cisco1',
                        api_endpoint=netbox_url, token=netbox_token)[0].value.address | ipaddr('address')}}"
            dns: ""
            port: "161"
        macros:
          - macro: '{$SNMP_COMMUNITY}'
            value: router

実行

# ansible-playbook -i hosts netbox-zabbix-add.yml 

PLAY [zabbix] *******************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************
ok: [192.168.100.14]

TASK [create host] **************************************************************************************************************************************************************************
changed: [192.168.100.14 -> localhost]

PLAY RECAP **********************************************************************************************************************************************************************************
192.168.100.14             : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

確認

登録されていることを確認

f:id:HiRo1325:20220113023902p:plain

終わりに

なかなか記事の更新ができていないが、備忘録として今後はnetbox/ansible関連の書いていく。 Azure/VMware等にも取り組もうと考えてます。

pyATS/GenieでOSPFの設定をしてみた。

はじめに

久しぶりのブログ更新。
今日はpyats/Genieの自動化の第2弾としてospfの設定を行う。

動作環境

  1. OS
    ubuntu on ESXi
    CSR1000v on ESXi

  2. 言語
    python

目次

検証トポロジー

トポロジーはこちら。

f:id:HiRo1325:20210701010504p:plain

IOSには対応してない為、今回はCSR1000vにのみ自動化を行っている

自動化するコンフィグ

CSR1000vのインターフェースのIPアドレス設定とOSPF設定を自動化します。
自動化対象のコマンドはこちらです。

!
interface GigabitEthernet2
 description pyats-ospf-conf
 ip address 192.168.10.1 255.255.255.0
 negotiation auto
!
router ospf 1
 router-id 1.1.1.1
 network 192.168.10.0 0.0.0.255 area 2
!

作成したスクリプト

スクリプトはこちらになります。

github.com

実行

実行

python ospf.py

結果ログ

[2021-07-01 00:00:55,504] +++ csr1 logfile /tmp/csr1-cli-20210701T000055502.log +++
[2021-07-01 00:00:55,505] +++ Unicon plugin iosxe +++
Trying 192.168.100.21...

[2021-07-01 00:00:55,533] +++ connection to spawn: telnet 192.168.100.21, id: 140434380597856 +++
[2021-07-01 00:00:55,533] connection to csr1
Connected to 192.168.100.21.
Escape character is '^]'.


User Access Verification

Username: csr1
Password:
csr1>
[2021-07-01 00:00:57,766] +++ initializing handle +++
enable
Password:
csr1#
[2021-07-01 00:00:57,799] +++ csr1: executing command 'term length 0' +++
term length 0
csr1#
[2021-07-01 00:00:57,961] +++ csr1: executing command 'term width 0' +++
term width 0
csr1#
[2021-07-01 00:00:58,134] +++ csr1: executing command 'show version' +++
show version
Cisco IOS XE Software, Version 03.15.00.S - Standard Support Release
Cisco IOS Software, CSR1000V Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 15.5(2)S, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2015 by Cisco Systems, Inc.
Compiled Sun 22-Mar-15 01:36 by mcpre


Cisco IOS-XE software, Copyright (c) 2005-2015 by cisco Systems, Inc.
All rights reserved.  Certain components of Cisco IOS-XE software are
licensed under the GNU General Public License ("GPL") Version 2.0.  The
software code licensed under GPL Version 2.0 is free software that comes
with ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such
GPL code under the terms of GPL Version 2.0.  For more details, see the
documentation or "License Notice" file accompanying the IOS-XE software,
or the applicable URL provided on the flyer accompanying the IOS-XE
software.


ROM: IOS-XE ROMMON

csr1 uptime is 38 minutes
Uptime for this control processor is 40 minutes
System returned to ROM by reload
System image file is "bootflash:packages.conf"
Last reload reason: <NULL>



This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html

If you require further assistance please contact us by sending email to
export@cisco.com.

License Level: ax
License Type: Default. No valid license found.
Next reload license Level: ax

cisco CSR1000V (VXE) processor (revision VXE) with 701398K/6147K bytes of memory.
Processor board ID 9JLL2WTI8I5
2 Gigabit Ethernet interfaces
32768K bytes of non-volatile configuration memory.
1989912K bytes of physical memory.
16162815K bytes of virtual hard disk at bootflash:.

Configuration register is 0x2102

csr1#
[2021-07-01 00:00:58,449] +++ csr1: config +++
config term
Enter configuration commands, one per line.  End with CNTL/Z.
csr1(config)#no logging console
csr1(config)#line console 0
csr1(config-line)#exec-timeout 0
csr1(config-line)#end
csr1#
[2021-07-01 00:00:58,711] +++ csr1: executing command 'show run' +++
show run
Building configuration...

Current configuration : 1097 bytes
!
! Last configuration change at 14:48:25 UTC Wed Jun 30 2021 by csr1
!
version 15.5
service timestamps debug datetime msec
service timestamps log datetime msec
no platform punt-keepalive disable-kernel-core
platform console auto
!
hostname csr1
!
boot-start-marker
boot-end-marker
!
!
no logging console
enable password csr1
!
no aaa new-model
!
ip vrf VRF1
 rd 1:100
!
!
!
!
!
!
!
!
!


ip domain name csr.com

!
!
!
!
!
!
!
!
!
!
subscriber templating
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
!
!
license udi pid CSR1000V sn 9JLL2WTI8I5
spanning-tree extend system-id
!
username csr1 password 0 csr1
!
redundancy
!
!
!
!
!
!
ip ssh version 2
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface GigabitEthernet1
 ip address 192.168.100.21 255.255.255.0
 negotiation auto
!
interface GigabitEthernet2
 no ip address
 negotiation auto
!
!
virtual-service csr_mgmt
!
ip forward-protocol nd
!
no ip http server
no ip http secure-server
!
!
!
!
control-plane
!
 !
 !
 !
 !
!
!
!
!
!
line con 0
 exec-timeout 0 0
line vty 0 4
 exec-timeout 0 0
 login local
 transport input all
!
!
end

csr1#
{'csr1': <genie.conf.base.config.CliConfig object at 0x7fb969b0be50>}
[2021-07-01 00:00:59,256] +++ csr1: config +++
config term
Enter configuration commands, one per line.  End with CNTL/Z.
csr1(config)#interface GigabitEthernet2
csr1(config-if)# description pyats-ospf-conf
csr1(config-if)# ip address 192.168.10.1 255.255.255.0
csr1(config-if)# no shutdown
csr1(config-if)# exit
csr1(config)#end
csr1#
[2021-07-01 00:00:59,857] +++ csr1: config +++
config term
Enter configuration commands, one per line.  End with CNTL/Z.
csr1(config)#router ospf 1
csr1(config-router)# no shutdown
csr1(config-router)# router-id 1.1.1.1
csr1(config-router)# network 192.168.10.0 0.0.0.255 area 2
csr1(config-router)# exit
csr1(config)#end
csr1#
[2021-07-01 00:01:00,345] +++ csr1: executing command 'show run' +++
show run
Building configuration...

Current configuration : 1224 bytes
!
! Last configuration change at 14:48:27 UTC Wed Jun 30 2021 by csr1
!
version 15.5
service timestamps debug datetime msec
service timestamps log datetime msec
no platform punt-keepalive disable-kernel-core
platform console auto
!
hostname csr1
!
boot-start-marker
boot-end-marker
!
!
no logging console
enable password csr1
!
no aaa new-model
!
ip vrf VRF1
 rd 1:100
!
!
!
!
!
!
!
!
!


ip domain name csr.com

!
!
!
!
!
!
!
!
!
!
subscriber templating
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
!
!
license udi pid CSR1000V sn 9JLL2WTI8I5
spanning-tree extend system-id
!
username csr1 password 0 csr1
!
redundancy
!
!
!
!
!
!
ip ssh version 2
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface GigabitEthernet1
 ip address 192.168.100.21 255.255.255.0
 negotiation auto
!
interface GigabitEthernet2
 description pyats-ospf-conf
 ip address 192.168.10.1 255.255.255.0
 negotiation auto
!
router ospf 1
 router-id 1.1.1.1
 network 192.168.10.0 0.0.0.255 area 2
!
!
virtual-service csr_mgmt
!
ip forward-protocol nd
!
no ip http server
no ip http secure-server
!
!
!
!
control-plane
!
 !
 !
 !
 !
!
!
!
!
!
line con 0
 exec-timeout 0 0
line vty 0 4
 exec-timeout 0 0
 login local
 transport input all
!
!
end

ここまでの結果がconfigの自動設定になる。

cofigの修正前と修正後の比較の結果はこちらになります。

csr1#
+Current configuration : 1224 bytes:
+router ospf 1:
+ network 192.168.10.0 0.0.0.255 area 2:
+ router-id 1.1.1.1:
-Current configuration : 1097 bytes:
interface GigabitEthernet2:
+ description pyats-ospf-conf:
+ ip address 192.168.10.1 255.255.255.0:
- no ip address:

確認

  1. neighborの確認
csr1#show ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   FULL/DR         00:00:35    192.168.10.2    GigabitEthernet2

自動化後にneighborが形成されているかも確認。

参考資料

pyATS/Genie初回環境構築は前回の記事を参考にしてください。

hiro1325.hatenablog.com

終わりに

次はより多くのconfigの自動化のスクリプト作成にチャレンジ行う。
ご意見があればよろしくお願いします。

cEOSをAnsibleで自動化を試してみた

はじめに

今回はAristaが提供しているcEOSをAnsibleで操作できるかやってみる。
実験内容としてはvlan 1にIPアドレスを設定するplay-booksにて設定されるかを確認する。

動作環境

Mac OS(cEOS on Docker)

目次

検証内容

前回dockerコンテナとしてAristaのcEOSを構築した記事を挙げた。

hiro1325.hatenablog.com

構築方法は前回の記事も踏まえて参考にしていただけると幸いです。
今回は前回とコンテナの作成のパラメーターが若干違うため、起動パラメーターのみ環境構築の章にて記述する。

環境構築

cEOS のdockerコンテナ作成のパラメーター

docker create --name=ceos2 --privileged -p 25022:22 -e INTFTYPE=eth -e ETBA=1 -e SKIP_ZEROTOUCH_BARRIER_IN_SYSDBINIT=1 -e CEOS=1 -e EOS_PLATFORM=ceoslab -e container=docker -i -t ceos:latest /sbin/init systemd.setenv=INTFTYPE=eth systemd.setenv=ETBA=1 systemd.setenv=SKIP_ZEROTOUCH_BARRIER_IN_SYSDBINIT=1 systemd.setenv=CEOS=1 systemd.setenv=EOS_PLATFORM=ceoslab systemd.setenv=container=docker

作成できたらdockerネットワークの設定などが残っているが前回の記事に記載がるのでそちらを参考に。

起動できたらコンテナにCliログイン

docker exec -it ceos2 Cli

ログインできたらグローバルコンフィギュレーションモードにてユーザーとパスワード設定を行う。

(config)#username arista privilege 15 secret arista

ここまで設定できたら作成したceos2コンテナにsshでログインできるか試してみる。

$ssh arista@localhost -p 25022
Password:
localhost>

事前にvlan 1にIPが設定されていないことを確認できれば事前準備は完了

localhost#show interfaces vlan 1
% Interface does not exist

Play-books作成と実行

インベントリーファイルの中身はこちら

[ceos2]
localhost
[ceos2:vars]
ansible_user=arista
ansible_password=arista
ansible_connection=network_cli
ansible_network_os=eos
ansible_ssh_pass=arista
ansible_port=25022
ansible_become=yes
ansible_become_method=enable
ansible_become_pass=arista

play-booksの中身はこちら

- hosts: ceos2
  gather_facts: no
  tasks:
    - name: show version
      eos_config:
        parents: interface vlan 1
        lines: ip address 192.168.1.1 255.255.255.0

ここまで出来れば後は実行

$ansible-playbook -i hosts setvlan.yml
PLAY [ceos2] ***********************************************************************************************************************************************************************************************

TASK [show version] ****************************************************************************************************************************************************************************************
[WARNING]: Platform darwin on host localhost is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
changed: [localhost]

PLAY RECAP *************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

結果確認

設定できたか確認した内容はこちら

localhost#show int vlan 1
Vlan1 is up, line protocol is up (connected)
  Hardware is Vlan, address is 0242.ac11.3eb8 (bia 0242.ac11.3eb8)
  Internet address is 192.168.1.1/24
  Broadcast address is 255.255.255.255
  IP MTU 1500 bytes (default)
  Up 3 minutes, 32 seconds

さいごに

AnsibleにてcEOSのコンテナに対して自動化が可能な為、実機を購入する必要がなくなる。 実機購入を躊躇っている人にはこの方法でネットワーク機器の自動化を学習するのが良いと思う。

今後はコンテナを増やしてルーティングを行う為のplay-booksを作成しようと考えている。

batfishを使ってみた

はじめに

今まではAnsibleを使ったconfigの自動的に機器に設定するなどやってきた。
しかし、ネットワークconfigの検証の記事がかけてないと思い。
そこでネットワークconfig分析を行うためにbatfishというツールを使ってみた。

動作環境

Docker on Mac OS

目次

検証内容

R1.cfg/R2.cfgといった2つのconfigを用意 configの中身はシンプルにIPアドレスが重複してるものとなっている。 そのconfigをbatfishにて被っているかを検出する。

環境構築

まずは環境構築

batfishのコンテナが提供されている為それを使用する。
下記が今回使用するコンテナイメージである。
・batfish/allinone

コンテナを起動

docker run -d -p 8888:8888 --name batfish batfish/allinone

すると下記のように起動していることを確認。

$docker ps
CONTAINER ID   IMAGE                            COMMAND                  CREATED              STATUS              PORTS                                      NAMES
a720fad08ed5   batfish/allinone                 "./wrapper.sh"           About a minute ago   Up About a minute   0.0.0.0:8888->8888/tcp, 9996-9997/tcp      batfish

検証対象のconfig

・R1.cfg

hostname R1
!
enable password cisco
!
username cisco password 0 cisco
no aaa new-model
!
interface Vlan1
 ip address 192.168.100.20 255.255.255.0
!
end

・R2.cfg

hostname R2
!
enable password cisco
!
username cisco password 0 cisco
no aaa new-model
!
interface Vlan1
 ip address 192.168.100.20 255.255.255.0
!
end

上記のcfgファイルをコンテナのconfigsディレクトリにコピーして置いてください。
コピー方法は下記です。

docker cp R1.cfg batfish:/notebooks/networks/example/batfish_test/configs
docker cp R2.cfg batfish:/notebooks/networks/example/batfish_test/configs

batfish_testディレクトリに関して今回検証用に作成したディレクトリであるため好きな名前のディレクトリで実施してください。
デフォルトではexampleディレクトリが用意されておりそれでも大丈夫です。
ディレクトリを新たに作成する場合、配下にconfigディレクトリとhostsディレクトリとiptablesディレクトリがあることに注意してください。

検証

このコンテナには既にbatfishを動かす為の、pybatfishがinstallされている為、
batfishコンテナでpython3を実行して検証を行う。
対象のコンテナで特定のコマンドを実行させる方法は下記です。

docker exec -it batfish python3

対象のコンテナでpython3を実行できたら下記にて必要なモジュールと設定ファイルを読み込みます。
bf_init_snapshotのパラメーターは個人のものに合わせてください。

>>> from pybatfish.client.commands import *
>>> from pybatfish.question.question import load_questions
>>> from pybatfish.question import bfq
>>> load_questions()
Successfully loaded 64 questions from remote
Successfully loaded 64 questions from remote
>>> bf_init_snapshot('/notebooks/networks/example/batfish_test/', name='test', overwrite=True)
status: TRYINGTOASSIGN
.... no task information
status: TRYINGTOASSIGN
.... no task information
status: CHECKINGSTATUS
.... no task information
status: CHECKINGSTATUS
.... no task information
status: CHECKINGSTATUS
.... no task information
status: CHECKINGSTATUS
.... 2021-04-11 14:51:35.363000+00:00 Serializing 'org.batfish.representation.host.HostConfiguration' instances to disk 0 / 2.
status: CHECKINGSTATUS
.... 2021-04-11 14:51:35.363000+00:00 Serializing 'org.batfish.representation.host.HostConfiguration' instances to disk 2 / 2.
status: CHECKINGSTATUS
.... 2021-04-11 14:51:35.363000+00:00 Parse network configs 0 / 2. (00:00:05 elapsed)
status: CHECKINGSTATUS
.... 2021-04-11 14:51:35.363000+00:00 Serializing 'org.batfish.representation.cisco.CiscoConfiguration' instances to disk 0 / 2. (00:00:07 elapsed)
status: CHECKINGSTATUS
.... 2021-04-11 14:51:35.363000+00:00 Reading, unpacking, and deserializing files containing 'org.batfish.vendor.VendorConfiguration' instances 2 / 4. (00:00:08 elapsed)
status: CHECKINGSTATUS
.... 2021-04-11 14:51:35.363000+00:00 Serializing 4 vendor-independent configuration structures for snapshot a3779dc8-c69e-4307-b786-24e2fd3a1335 0 / 4. (00:00:11 elapsed)
status: CHECKINGSTATUS
.... 2021-04-11 14:51:35.363000+00:00 Deserializing objects of type 'org.batfish.datamodel.Configuration' from files 4 / 4. (00:00:13 elapsed)
status: TERMINATEDNORMALLY
.... 2021-04-11 14:51:35.363000+00:00 Deserializing objects of type 'org.batfish.datamodel.Configuration' from files 4 / 4. (00:00:17 elapsed)
Default snapshot is now set to test
status: CHECKINGSTATUS
.... no task information
status: CHECKINGSTATUS
.... 2021-04-11 14:51:57.425000+00:00 Begin job.
status: TERMINATEDNORMALLY
.... 2021-04-11 14:51:57.425000+00:00 Begin job.
'test'

次でIPアドレス被りがあるか確認できる。

>>> bfq.ipOwners(duplicatesOnly=True).answer().frame()
status: TRYINGTOASSIGN
.... no task information
status: CHECKINGSTATUS
.... no task information
status: CHECKINGSTATUS
.... no task information
status: CHECKINGSTATUS
.... 2021-04-11 14:52:53.437000+00:00 Begin job.
status: TERMINATEDNORMALLY
.... 2021-04-11 14:52:53.437000+00:00 Begin job.
  Node      VRF Interface              IP Mask Active
0   r2  default     Vlan1  192.168.100.20   24   True
1   r1  default     Vlan1  192.168.100.20   24   True

参考資料

pybatfish.readthedocs.io

おわりに

本ツールは他にも様々な検証に使えるため、色々と使って記事にしようと思う。