AnsibleでCisco Nexusのコンフィグバックアップを取得する。

事前準備

以下の機器やAnsibleがインストールされているサーバを用意する。

  • Ansibleホストサーバの立ち上げ(CentOS7)
  • Nexus機の用意
  • Ansibleのインストール
AnsibleホストサーバのOS情報
# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
Nexus機の情報
Software
  BIOS: version 07.65
 NXOS: version 9.2(3)
  BIOS compile time:  09/04/2018
  NXOS image file is: bootflash:///nxos.9.2.3.bin
  NXOS compile time:  2/17/2019 5:00:00 [02/18/2019 00:07:27]
Ansibleバージョン
# ansible --version
ansible 2.4.2.0

作業ディレクトリ構造

etc/
 ┗ansible/
   ┃ 
   ┠hosts
   ┃ 
   ┠backups
   ┃
   ┗show_run_cisco.yaml

hosts/show_run_cisco.yamlの内容

  • hosts
[cisco]
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
- hosts: cisco
  gather_facts: no
  connection: local

  tasks:
   - name: show run
     ios_command:
       commands:
         - show run
       host: "{{ inventory_hostname }}"
       username: admin
       password: admin
     register: config

   - name: save output to /etc/ansible/backups
     copy:
       content: "{{ config.stdout[0] }}"
       dest: "/etc/ansible/backups/show_run_{{ inventory_hostname }}.txt"

実行結果

# ansible-playbook show_run_cisco.yaml

PLAY [cisco] **********************************************************************************************

TASK [show run] *******************************************************************************************
 [WARNING]: argument username has been deprecated and will be removed in a future version

 [WARNING]: argument host has been deprecated and will be removed in a future version

 [WARNING]: argument password has been deprecated and will be removed in a future version

ok: [192.168.1.1]
ok: [192.168.1.2]
ok: [192.168.1.3]
ok: [192.168.1.4]
ok: [192.168.1.5]
ok: [192.168.1.6]

TASK [save output to /etc/ansible/backups] ****************************************************************
changed: [192.168.1.1]
changed: [192.168.1.2]
changed: [192.168.1.3]
changed: [192.168.1.4]
changed: [192.168.1.5]
changed: [192.168.1.6]

PLAY RECAP ************************************************************************************************
192.168.1.1               : ok=2    changed=1    unreachable=0    failed=0
192.168.1.2               : ok=2    changed=1    unreachable=0    failed=0
192.168.1.3               : ok=2    changed=1    unreachable=0    failed=0
192.168.1.4               : ok=2    changed=1    unreachable=0    failed=0
192.168.1.5               : ok=2    changed=1    unreachable=0    failed=0
192.168.1.6               : ok=2    changed=1    unreachable=0    failed=0
#

バックアップコンフィグも保存されている

# ls /etc/ansible/backups/ | grep show_run_1
show_run_192.168.2.47.txt
show_run_192.168.2.56.txt
show_run_192.168.2.57.txt
show_run_192.168.2.58.txt
show_run_192.168.2.59.txt
show_run_192.168.2.60.txt
#

実行時にWariningが出ていますが、動作に影響がないので今は無視します。
エラー内容としては今後username , host , password が使えなくなるよと言っていますね。