DELL EMC ネットワークスイッチをAnsibleする


CiscoやJuniperをAnsibleで操作する記事は多数ありますが、DellEMC ネットワークスイッチの日本語記事はあまりみかけないので書いておきます。

*本記事はOS10を想定しています。

  1. Ansibleをインストール

Ubuntu18.10の例です。Ansibleが入っていない場合のみ実行してください。

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt update
$ sudo apt install ansible
  1. サンプル入手

GithubでAnsibleプレイブックのサンプルが公開されていますので入手します。

$ git clone https://github.com/Dell-Networking/ansible-dellos-exampless

3.inventory.yaml編集

操作する対象スイッチのIPアドレスを書きます。

$ cd ansible-dellos-examples/
$ vim inventory.yaml

[dellos10]
dellos10_sw1 ansible_host=10.118.41.69
  1. スイッチのパラメータファイルを編集する

SSHログインするためのユーザ名/パスワードを書いておきます。

$ vim host_vars/dellos10_sw1.yaml

hostname: dellos10_sw1                           

# parametes for connection type network_cli      
ansible_ssh_user: admin                          
ansible_ssh_pass: xxxxxx
ansible_network_os: dellos10                     
  1. 実行してみる

例: コンフィグの表示

$ ansible-playbook -i inventory.yaml showver_os10.yaml

PLAY [dellos10] ********************************************************************************************************


TASK [Get Dell EMC OS10 Show version] **********************************************************************************

ok: [dellos10_sw1]

TASK [debug] ***********************************************************************************************************

ok: [dellos10_sw1] => {
    "show_ver": {
        "changed": false,
        "failed": false,
        "stdout": [
            "Dell EMC Networking OS10 Enterprise\nCopyright (c) 1999-2018 by Dell Inc. All Rights Reserved.\nOS Version: 10.3.2E(R2)\nBuild Version: 10.3.2E(R2.146)\nBuild Time: 2018-03-20T13:36:07-0700\nSystem Type: S5148F-ON\nArchitecture: x86_64\nUp Time: 5 weeks 4 days 02:31:35"
        ],
        "stdout_lines": [
            [
                "Dell EMC Networking OS10 Enterprise",
                "Copyright (c) 1999-2018 by Dell Inc. All Rights Reserved.",
                "OS Version: 10.3.2E(R2)",
                "Build Version: 10.3.2E(R2.146)",
                "Build Time: 2018-03-20T13:36:07-0700",
                "System Type: S5148F-ON",
                "Architecture: x86_64",
                "Up Time: 5 weeks 4 days 02:31:35"
            ]
        ]
    }
}

PLAY RECAP *************************************************************************************************************

dellos10_sw1               : ok=2    changed=0    unreachable=0    failed=0

例2: ホスト名の設定
ホスト名をdellsw1 に変更する

$ ansible-playbook -i inventory.yaml --extra-vars "hostname=dellsw1" hostname_os10.yaml

PLAY [dellos10] ********************************************************************************************************


TASK [Set the hostname for the Dell EMC OS10 Device] *******************************************************************

changed: [dellos10_sw1]

TASK [debug] ***********************************************************************************************************

ok: [dellos10_sw1] => {
    "set_hostname": {
        "changed": true,
        "commands": [
            "hostname dellsw1",
            "commit"
        ],
        "failed": false,
        "saved": false,
        "updates": [
            "hostname dellsw1",
            "commit"
        ]
    }
}

PLAY RECAP *************************************************************************************************************

dellos10_sw1               : ok=2    changed=1    unreachable=0    failed=0

ホスト名が変わったことの確認

$ ssh -l admin 10.118.41.69                                   
[email protected]'s password:                                                                                          

The programs included with the Debian GNU/Linux system are free software;                                               
the exact distribution terms for each program are described in the                                                      
individual files in /usr/share/doc/*/copyright.                                                                         

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent                                                       
permitted by applicable law.                                                                                            


-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-                                                       
-*         Dell EMC  Network Operating System (OS10)           *-                                                       
-*                                                             *-                                                       
-* Copyright (c) 1999-2017 by Dell Inc. All Rights Reserved.   *-                                                       
-*                                                             *-                                                       
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-                                                       

This product is protected by U.S. and international copyright and                                                       
intellectual property laws. Dell EMC and the Dell EMC logo are                                                          
trademarks of Dell Inc. in the United States and/or other                                                               
jurisdictions. All other marks and names mentioned herein may be                                                        
trademarks of their respective companies.                                                                               

Last login: Thu Dec 27 14:35:19 2018 from 10.118.38.181                                                                 
dellsw1#