Ansible:FortiGate のスタティックルートを設定する

ネットワーク

作業環境

■ Ansible 側

  • CentOS 8.0
  • Python 3.7.7
  • Ansible 2.9.6

■ FortiGate 側

  • 型番:FortiGate 60E
  • バージョン:v6.0.6 build0272 (GA)

fortios_router_static モジュール

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

  • スタティックルートの追加/削除/設定変更

のために利用できます。

主なパラメータ

パラメータ必須選択肢/デフォルト説明
host対象機器のIPアドレス
usernameSSH用のユーザ
password・”” ←SSH用のパスワード
vdom・root ←対象機器のバーチャルドメイン
https・no
・yes ←
HTTPSを使用するかどうか
ssl_verify・no
・yes ←
対象機器の証明書を検証するかどうか
state・present
・absent
対象スタティックルートが
・present ⇒ 存在する(追加/変更)
・absent ⇒ 存在しない(削除)
※Ansible 2.9 からはこのレベルで指定
router_staticconfig router static の設定項目を
子要素として指定する
 – state・present
・absent
対象スタティックルートが
・present ⇒ 存在する(追加/変更)
・absent ⇒ 存在しない(削除)
※Ansible 2.8 ではこのレベルで指定
 – seq_num対象スタティックルートの ID 番号
 – status・enable
・disable
状態
 – dst宛先
 – gatewayネクストホップアドレス
 – distanceディスタンス
 – weight重み
 – priorityプライオリティ
 – device送出インターフェース

備考

  • Ansible 2.8 から追加されたモジュール
  • Legacy モードでの実行のためには fortiosapi が必要
  • httpapi での実行が可能
  • seq_num を指定しない、かつ state = present の場合、seq_num は以下のようになる
    • 既存ルートが存在する ⇒ (既存の最大 ID) + 1
    • 既存ルートが存在しない ⇒ 1

使用例

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

スタティックルート追加

以下の要件でスタティックルートを追加することとします。

  • シーケンス番号:1
  • 宛先:0.0.0.0 0.0.0.0
  • ネクストホップ:10.20.40.254
  • ディスタンス:10
  • 重み:0
  • プライオリティ:0
  • 送出インターフェース:wan1

■ Playbook:playbook.yml

- hosts: all
  gather_facts: no
  tasks:
    - name: "fortios_router_static test"
      fortios_router_static:
        vdom: "root"
        state: "present"
        router_static:
          seq_num: "1"
          status: "enable"
          dst: "0.0.0.0 0.0.0.0"
          gateway: "10.20.40.254"
          distance: "10"
          weight: "0"
          priority: "0"
          device: "wan1"

■ Playbook 実行

# ansible-playbook -i hosts playbook.yml

PLAY [all] **********************************************************************************************************

TASK [fortios_router_static 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 router static
config router static
end

■ 実行後の FortiGate のコンフィグ

FGT # show router static
config router static
    edit 1
        set gateway 10.20.40.254
        set device "wan1"
    next
end

FGT # show full-configuration router static
config router static
    edit 1
        set status enable
        set dst 0.0.0.0 0.0.0.0
        set gateway 10.20.40.254
        set distance 10
        set weight 0
        set priority 0
        set device "wan1"
        set comment ''
        set blackhole disable
        set dynamic-gateway disable
        set virtual-wan-link disable
        set dstaddr ''
        unset internet-service
        set internet-service-custom ''
        set link-monitor-exempt disable
        set bfd disable
    next
end

スタティックルート削除

上の例で追加したスタティックルートを削除します。

■ Playbook:playbook.yml

- hosts: all
  gather_facts: no
  tasks:
    - name: "fortios_router_static test"
      fortios_router_static:
        vdom: "root"
        state: "absent"
        router_static:
          seq_num: "1"

■ Playbook 実行

# ansible-playbook -i hosts playbook.yml

PLAY [all] **********************************************************************************************************

TASK [fortios_router_static 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 router static
config router static
end

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

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