作業環境
■ Ansible 側
- CentOS 8.0
- Python 3.7.7
- Ansible 2.9.6
■ FortiGate 側
- 型番:FortiGate 60E
- バージョン:v6.0.6 build0272 (GA)
fortios_system_snmp_sysinfo モジュール
fortios_system_snmp_sysinfo モジュールを使用することで FortiGate のコンフィグにおける config system snmp sysinfo の各項目を設定することができます。
- SNMP エージェントの有効/無効の設定
などのために利用できます。
主なパラメータ
パラメータ | 必須 | 選択肢/デフォルト | 説明 |
host | 対象機器のIPアドレス | ||
username | SSH用のユーザ | ||
password | ・”” ← | SSH用のパスワード | |
vdom | ・root ← | 対象機器のバーチャルドメイン | |
https | ・no ・yes ← | HTTPSを使用するかどうか | |
ssl_verify | ・no ・yes ← | 対象機器の証明書を検証するかどうか | |
system_snmp_sysinfo | config system snmp sysinfo の設定項目を 子要素として指定する | ||
– status | ・enable ・disable | SNMP エージェントの有効/無効 |
備考
- Ansible 2.9 から追加されたモジュール
- Legacy モードでの実行のためには fortiosapi が必要
- httpapi での実行が可能
使用例
httpapi を使用してモジュールを実行する例です。
■ インベントリ:hosts
[forti]
10.1.10.100
[forti:vars]
ansible_user=admin
ansible_password=password
ansible_network_os=fortios
ansible_connection=httpapi
ansible_httpapi_use_ssl=yes
ansible_httpapi_validate_certs=no
10.1.10.100 は操作対象の FortiGate のIPアドレスです。
httpapi で使用する変数をグループ変数として定義しています。
SNMP エージェントの有効化
■ Playbook:playbook.yml
- hosts: all
gather_facts: no
tasks:
- name: "fortios_system_snmp_sysinfo test"
fortios_system_snmp_sysinfo:
vdom: "root"
system_snmp_sysinfo:
status: "enable"
■ Playbook 実行
# ansible-playbook -i hosts playbook.yml
PLAY [all] **********************************************************************************************************
TASK [fortios_system_snmp_sysinfo test] *****************************************************************************
changed: [10.1.10.100]
PLAY RECAP **********************************************************************************************************
10.1.10.100 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
■ 実行前の FortiGate のコンフィグ
FGT # show system snmp sysinfo
config system snmp sysinfo
end
■ 実行後の FortiGate のコンフィグ
FGT # show system snmp sysinfo
config system snmp sysinfo
set status enable
end
fortios_system_snmp_community モジュール
fortios_system_snmp_community モジュールを使用することで FortiGate のコンフィグにおける config system snmp community の各項目を設定することができます。
- SNMP コミュニティの追加/削除/変更
のために利用できます。
主なパラメータ
パラメータ | 必須 | 選択肢/デフォルト | 説明 |
host | 対象機器のIPアドレス | ||
username | SSH用のユーザ | ||
password | ・”” ← | SSH用のパスワード | |
vdom | ・root ← | 対象機器のバーチャルドメイン | |
https | ・no ・yes ← | HTTPSを使用するかどうか | |
ssl_verify | ・no ・yes ← | 対象機器の証明書を検証するかどうか | |
state | ● | ・present ・absent | 対象コミュニティが ・present ⇒ 存在する(追加/変更) ・absent ⇒ 存在しない(削除) |
system_snmp_community | config system snmp community の 設定項目を子要素として指定する | ||
– id | ● | 対象コミュニティの ID 番号 | |
– name | コミュニティ名 | ||
– status | ・enable ・disable | 状態 | |
– hosts | SNMP サーバの設定を子要素に指定 | ||
– id | ● | SNMP サーバの ID 番号 | |
– ip | SNMP サーバの IPアドレス | ||
– host_type | ・any ・query ・trap | SNMP サーバのタイプ | |
– source_ip | SNMP サーバとの通信で使用する IPアドレス | ||
– query_v1_status | ・enable ・disable | クエリ v1 有効/無効 | |
– query_v1_port | クエリ v1 ポート | ||
– query_v2c_status | ・enable ・disable | クエリ v2c 有効/無効 | |
– query-v2c-port | クエリ v2c ポート | ||
– trap_v1_status | ・enable ・disable | トラップ v1 有効/無効 | |
– trap-v1-lport | トラップ v1 ローカルポート | ||
– trap-v1-rport | トラップ v1 リモートポート | ||
– trap_v2c_status | ・enable ・disable | トラップ v2c 有効/無効 | |
– trap-v2c-lport | トラップ v2c ローカルポート | ||
– trap-v2c-rport | トラップ v2c リモートポート | ||
– events | SNMPイベント |
備考
- Ansible 2.9 から追加されたモジュール
- Legacy モードでの実行のためには fortiosapi が必要
- httpapi での実行が可能
使用例
httpapi を使用してモジュールを実行する例です。
■ インベントリ:hosts
上述の fortios_system_snmp_sysinfo モジュールの使用例と同様の内容とします。
SNMP コミュニティ追加
以下の要件で SNMP コミュニティを追加することとします。
- コミュニティ ID:1
- コミュニティ名:hogepiyo
- SNMP サーバ
- ID:1
- IPアドレス:10.1.10.4
- タイプ:any
- ソースIP:0.0.0.0
- SNMP使用バージョン:v2c のみ
- 他:デフォルト
■ Playbook:playbook.yml
- hosts: all
gather_facts: no
tasks:
- name: "fortios_system_snmp_community test"
fortios_system_snmp_community:
vdom: "root"
state: "present"
system_snmp_community:
id: "1"
name: "hogepiyo"
status: "enable"
hosts:
- id: "1"
ip: "10.1.10.4"
host_type: "any"
source_ip: "0.0.0.0"
query_v1_status: "disable"
query_v2c_status: "enable"
trap_v1_status: "disable"
trap_v2c_status: "enable"
■ Playbook 実行
# ansible-playbook -i hosts playbook.yml
PLAY [all] **********************************************************************************************************
TASK [fortios_system_snmp_community test] ***************************************************************************
changed: [10.1.10.100]
PLAY RECAP **********************************************************************************************************
10.1.10.100 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
■ 実行前の FortiGate のコンフィグ
FGT # show full-configuration system snmp community
config system snmp community
end
■ 実行後の FortiGate のコンフィグ
FGT # show full-configuration system snmp community
config system snmp community
edit 1
set name "hogepiyo"
set status enable
config hosts
edit 1
set source-ip 0.0.0.0
set ip 10.1.10.4 255.255.255.255
set ha-direct disable
set host-type any
next
end
set query-v1-status disable
set query-v1-port 161
set query-v2c-status enable
set query-v2c-port 161
set trap-v1-status disable
set trap-v1-lport 162
set trap-v1-rport 162
set trap-v2c-status enable
set trap-v2c-lport 162
set trap-v2c-rport 162
set events cpu-high mem-low log-full intf-ip vpn-tun-up vpn-tun-down ha-switch ha-hb-failure ips-signature ips-anomaly av-virus av-oversize av-pattern av-fragmented fm-if-change bgp-established bgp-backward-transition ha-member-up ha-member-down ent-conf-change av-conserve av-bypass av-oversize-passed av-oversize-blocked ips-pkg-update ips-fail-open faz-disconnect wc-ap-up wc-ap-down fswctl-session-up fswctl-session-down load-balance-real-server-down per-cpu-high
next
end
SNMP コミュニティ削除
上の例で追加した SNMP コミュニティを削除します。
■ Playbook:playbook.yml
- hosts: all
gather_facts: no
tasks:
- name: "fortios_system_snmp_community test"
fortios_system_snmp_community:
vdom: "root"
state: "absent"
system_snmp_community:
id: "1"
■ Playbook 実行
# ansible-playbook -i hosts playbook.yml
PLAY [all] **********************************************************************************************************
TASK [fortios_system_snmp_community test] ***************************************************************************
changed: [10.1.10.100]
PLAY RECAP **********************************************************************************************************
10.1.10.100 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
■ 実行後の FortiGate のコンフィグ
FGT # show full-configuration system snmp community
config system snmp community
end
未解決問題
events が一つしか指定できない
system_snmp_community モジュールの events パラメータについて、モジュールの仕様上 string 型で指定する必要があり、値を一つしか指定できません。(「cpu-high」だけなど)
このため、events を指定すると指定した一つのイベントだけが有効化され、その他は無効化された状態になります。
■ Playbook 例
- hosts: all
gather_facts: no
tasks:
- name: "fortios_system_snmp_community test"
fortios_system_snmp_community:
vdom: "root"
state: "present"
system_snmp_community:
id: "1"
events: "cpu-high"
■ 実行後の FortiGate のコンフィグ
FGT # show system snmp community
config system snmp community
edit 1
set name "hogepiyo"
config hosts
edit 1
set ip 10.1.10.4 255.255.255.255
next
end
set query-v1-status disable
set trap-v1-status disable
set events cpu-high
next
end
ちなみに events の値をスペース区切りやコンマ区切りで複数指定したり、リスト形式で複数指定したりしてみましたがモジュールエラーとなりました。
コミュニティを新規作成する際に events を指定しなければ、FortiGate の仕様におけるデフォルトの設定状況になるため、要件として SNMP イベントが FortiGate の仕様上のデフォルトの状態で良い場合は何も指定しないという方法を採るしかないと思われます。
一方でデフォルト値から調整が必要な場合は Ansible は使えなさそうです。
―――――――――――――