Ansible:FortiGate のリンクモニタを設定する

ネットワーク

作業環境

■ Ansible 側

  • CentOS 8.0
  • Python 3.7.7
  • Ansible 2.9.6

■ FortiGate 側

  • 型番:FortiGate 60E
  • バージョン:v6.0.9

リンクモニタの設定

fortios_system_link_monitor モジュールを使用することで FortiGate のコンフィグにおける config system link-monitor の各項目を設定することができます。

  • リンクモニタの追加/変更/削除

に利用できます。

主なパラメータ

パラメータ必須選択肢/デフォルト説明
host対象機器のIPアドレス
usernameSSH用のユーザ
password・”” ←SSH用のパスワード
vdom・root ←対象機器のバーチャルドメイン
https・no
・yes ←
HTTPSを使用するかどうか
ssl_verify・no
・yes ←
対象機器の証明書を検証するかどうか
state・present
・absent
present ⇒ オブジェクト作成/変更
absent ⇒ オブジェクト削除
※Ansible 2.9 からはこのレベルで指定
system_link_monitor各設定項目を子要素に指定
 – nameリンクモニタ名
 – status・enable
・disable
ステータス
 – srcintfモニタ対象ルートの送出インターフェース
 – serverモニタ対象 IP アドレスをリストで指定
  – addressモニタ対象 IP アドレス
 – protocol・ping
・tcp-echo
・udp-echo
・http
・twamp
使用プロトコル
 – gateway_ipモニタ時のゲートウェイ
 – source_ipモニタ時に使用する送信元 IP アドレス
 – interval1 – 3600モニタ間隔(秒)
 – failtime1 – 10ダウンと判断する連続失敗回数のしきい値
 – recoverytime1 – 10復旧と判断する連続成功回数のしきい値
 – ha_priority1 – 50HA election priority
 – update_cascade_interface・enable
・disable
モニタ対象ダウン時に対象ルートの
送出インターフェースをダウンさせるか
 – update_static_route・enable
・disable
モニタ対象ダウン時に対象ルートを
ルーティングテーブルから削除するか

備考

  • 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 で使用する変数をグループ変数として定義しています。

リンクモニタの追加

■ Playbook:link-monitor_present.yml

- hosts: forti
  gather_facts: no
  tasks:
    - name: "add fortios_system_link_monitor"
      fortios_system_link_monitor:
        vdom: "root"
        state: "present"
        system_link_monitor:
          name: "hoge_monitor"
          status: "enable"
          srcintf: "wan1"
          server:
            - address: "192.168.179.1"
          protocol: "ping"
          gateway_ip: "0.0.0.0"
          source_ip: "0.0.0.0"
          interval: "1"
          failtime: "5"
          recoverytime: "5"
          ha_priority: "1"
          update_cascade_interface: "enable"
          update_static_route: "enable"

■ Playbook 実行

# ansible-playbook -i hosts link-monitor_present.yml

PLAY [forti] ********************************************************************************************************

TASK [add fortios_system_link_monitor] ******************************************************************************
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 link-monitor
config system link-monitor
    edit "hoge_monitor"
        set addr-mode ipv4
        set srcintf "wan1"
        set server "192.168.179.1"
        set protocol ping
        set gateway-ip 0.0.0.0
        set source-ip 0.0.0.0
        set interval 1
        set failtime 5
        set recoverytime 5
        set ha-priority 1
        set update-cascade-interface enable
        set update-static-route enable
        set status enable
    next
end

リンクモニタの削除

上の例で追加したリンクモニタを削除する例です。

■ Playbook:link-monitor_absent.yml

- hosts: forti
  gather_facts: no
  tasks:
    - name: "delete fortios_system_link_monitor"
      fortios_system_link_monitor:
        vdom: "root"
        state: "absent"
        system_link_monitor:
          name: "hoge_monitor"

■ Playbook 実行

# ansible-playbook -i hosts link-monitor_absent.yml

PLAY [forti] ********************************************************************************************************

TASK [delete fortios_system_link_monitor] ******************************************************************************
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

―――――――――――――

タイトルとURLをコピーしました