LoginSignup
4
1

More than 3 years have passed since last update.

ACIモードになっているCisco NexusのデバイスにAnsibleでコマンドを実行する

Last updated at Posted at 2020-02-17

背景

Leaf間の疎通テストをするために、ACIモードになっているCisco Nexusのデバイスからipingを自動で実行したい状況になったため、Ansibleで試してみました。

ですが、Ansible2.9現在ではACIモードになっているCisco Nexusでコマンドを実行するための
Ansible os platform typeが用意されていないため手を加える必要がありました。
※ansible_network_os: nxosをそのまま使うと、pingモジュールの応答は返ってきますがコマンドの実行はこちらと同じエラーとなりできません。

結論

結論としてaciモードではterminal lengthのコマンドが実行できない事が原因で上記のエラーとなっていたので、ACIモードのNexusでコマンドを実行するには以下のようにします。

host_vars/leaf01.yml(ファイル名は一例)

---
ansible_network_os: nxos

## 以下省略

そして以下のファイルの以下の箇所をコメントアウトします。
※どこでAnsibleが動いているかによって編集するファイルが異なります。
私の場合は以下のパスを編集しました。
~/pyenv/lib/python3.7/site-packages/ansible/plugins/terminal/nxos.py


def on_open_shell(self):
    try:
        for cmd in ('terminal length 0', 'terminal width 511'):
            self._exec_cli_command(cmd)
        except AnsibleConnectionFailure:
            raise AnsibleConnectionFailure('unable to set terminal parameters')

site.yml(ファイル名は一例)

---
- hosts: leaf01
  gather_facts: no
  # このままでは管理者権限がyesになっていると失敗するのでnoにする
  become: no

  tasks:
    - name: iPingを実行する
      nxos_command:
        commands: 
          - iping -V my_tenant:my_vrf 192.168.0.1

コメントにも記載しましたように、このままではbecome: yesになっていると失敗するのでbecome: noにして使います。おそらく、先ほど編集したnxos.pyで管理者権限に昇格する処理がaciモード用となっていないのが原因です。

以上、あくまでも暫定的な使い方ではありますがこのようにする事でコマンドの実行ができましたので投稿した次第です。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1