■ はじめに
ios_config
モジュールには、コンフィグのバックアップファイルを生成する際に利用するコマンドを show running-config
にするか、show running-config all または full
(以降 show run all
) にするかを決める、defaults
というオプションがあります。
今までこのオプションは、backup: yes
による、コンフィグバックアップの際は参照されませんでしたが、Ansible 2.5.3 で参照されるように仕様変更されました。
先にまとめると、backup: yes
による コンフィグバックアップに利用されるコマンドは以下の様にります。
Ansible バージョン | defaults: no (デフォルト) |
defaults: yes |
---|---|---|
2.4.4 | show run |
show run |
2.5.2 | show run all |
show run all |
2.5.3 | show run |
show run all |
この記事ではこの仕様変更について簡単に動作検証を行います。 上記表内の 2.4.4 のログは割愛します。
- 関連issue
■ ネットワーク機器側の事前確認
コンフィグバックアップの結果が show run
の結果なのか show run all
の結果なのかをあとの動産検証で判断するために、事前にネットワーク機器側で手動で両コマンドの結果を確認しておきます。
show run
の結果
ip-172-31-38-162#sh running-config Building configuration... Current configuration : 3852 bytes ! ! Last configuration change at 05:37:12 UTC Fri May 18 2018 by ec2-user ! version 16.7 service timestamps debug datetime msec (略)
show run all
の結果
ip-172-31-38-162#sh running-config all Building configuration... Current configuration with default configurations exposed : 350668 bytes ! ! Last configuration change at 05:37:12 UTC Fri May 18 2018 by ec2-user ! version 16.7 downward-compatible-config 16.7 no service log backtrace no service config no service exec-callback no service nagle service slave-log no service slave-coredump no service pad to-xot no service pad from-xot no service pad cmns service pad no service telnet-zeroidle no service tcp-keepalives-in no service tcp-keepalives-out service timestamps debug datetime mse (略)
上記は抜粋となりますが、 show run all
は version
のあとに数々の no
から始まるココンフィグが表示されるという特徴があることが分かりました。
■ 動作検証(Ansible 2.5.2)
仕様変更前の Ansible 2.5.2 で defaults: no
と、 defaults: yes
それぞれのケースで試します。
2.5.2 / defaults: no
Playbook
以下のように defaults: no
(デフォルトのため指定なしと同じ) の Playbook を用意します。
- hosts: ios gather_facts: no connection: network_cli tasks: - name: config backup ios_config: defaults: no # here backup: yes
コンフィグバックアップ結果
以下のコンフィグファイルが生成されした。
Building configuration... Current configuration with default configurations exposed : 350668 bytes ! ! Last configuration change at 05:37:12 UTC Fri May 18 2018 by ec2-user ! version 16.7 downward-compatible-config 16.7 no service log backtrace no service config no service exec-callback no service nagle (略)
このように、 show run
の結果となりました。
2.5.2 / defaults: yes
Playbook
以下のように defaults: yes
の Playbook を用意します。
- hosts: ios gather_facts: no connection: network_cli tasks: - name: config backup ios_config: defaults: yes # here backup: yes
コンフィグバックアップ結果
以下のコンフィグファイルが生成されした。
`` Building configuration...
Current configuration with default configurations exposed : 350668 bytes ! ! Last configuration change at 05:37:12 UTC Fri May 18 2018 by ec2-user ! version 16.7 downward-compatible-config 16.7 no service log backtrace no service config no service exec-callback no service nagle (略) ``
このように、先ほどと同じく show run all
の結果となりました。Ansible 2.5.2 では defaults
オプションが参照されていないことが分かります。
■ 動作検証(Ansible 2.5.3)
次に、仕様変更前の Ansible 2.5.3 で defaults: no
、 defaults: yes
それぞれのケースで試します。
2.5.3 / defaults: no
Playbook
以下のように defaults: no
(デフォルトのため指定なしと同じ) の Playbook を用意します。
- hosts: ios gather_facts: no connection: network_cli tasks: - name: config backup ios_config: defaults: no # here backup: yes
コンフィグバックアップ結果
以下のコンフィグファイルが生成されした。
Building configuration... Current configuration : 3852 bytes ! ! Last configuration change at 05:37:12 UTC Fri May 18 2018 by ec2-user ! version 16.7 service timestamps debug datetime msec service timestamps log datetime msec platform qfp utilization monitor load 80 no platform punt-keepalive disable-kernel-core platform console virtual (略)
このように、 show run
の結果となりました。
2.5.3 / defaults: yes
Playbook
以下のように defaults: yes
の Playbook を用意します。
- hosts: ios gather_facts: no connection: network_cli tasks: - name: config backup ios_config: defaults: yes # here backup: yes
コンフィグバックアップ結果
以下のコンフィグファイルが生成されした。
Building configuration... Current configuration with default configurations exposed : 350668 bytes ! ! Last configuration change at 05:37:12 UTC Fri May 18 2018 by ec2-user ! version 16.7 downward-compatible-config 16.7 no service log backtrace no service config no service exec-callback no service nagle (略)
このように、 show run all
の結果となりました。
Ansible 2.5.3 では defaults
オプションが参照されていることが分かります。
■ まとめ
Ansible 2.5.3 で ios_config モジュールのコンフィグバックアップ時に defaults オプションを参照するようになったこと確認しました。
もし、backup: yes
と defaults: yes
を併用されている場合は、挙動の変化にご注意いただければと思います。
参考 Ansible 2.5.3 CANGELOG
ansible/CHANGELOG-v2.5.rst at stable-2.5 · ansible/ansible · GitHub