作業環境
■ Ansible 側
- CentOS 8.0
- Python 3.7.7
- Ansible 2.9.6
■ FortiGate 側
- 型番:FortiGate 60E
- バージョン:v6.0.6 build0272 (GA)
fortios_system_ntp モジュール
fortios_system_ntp モジュールを使用することで FortiGate のコンフィグにおける config system ntp の各項目を設定することができます。
- NTP同期に関する設定
- NTPサーバモードの設定
などに利用できます。
主なパラメータ
パラメータ | 必須 | 選択肢/デフォルト | 説明 |
host | 対象機器のIPアドレス | ||
username | SSH用のユーザ | ||
password | ・”” ← | SSH用のパスワード | |
vdom | ・root ← | 対象機器のバーチャルドメイン | |
https | ・no ・yes ← | HTTPSを使用するかどうか | |
ssl_verify | ・no ・yes ← | 対象機器の証明書を検証するかどうか | |
system_ntp | config system ntp の設定項目を 子要素として指定する | ||
– interface | NTPサーバモードが有効の場合 リッスンするインターフェースを リスト形式で指定 | ||
– interface_name | インターフェース名 | ||
– ntpserver | NTPサーバをリスト形式で指定 | ||
– id | ● | NTPサーバのID | |
– server | NTPサーバのIPアドレス | ||
– ntpsync | ・enable ・disable | NTPサーバと時刻同期するかどうか | |
– server_mode | ・enable ・disable | NTPサーバとして動作させるかどうか | |
– source_ip | NTPサーバと通信する際のソースIP | ||
– syncinterval | 1 – 1440 | NTP同期間隔(分) | |
– type | ・fortiguard ・custom | NTPサーバの選択 ・fortiguard ⇒ fortiguard を使用 ・custom ⇒ カスタム設定とする |
備考
- 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 で使用する変数をグループ変数として定義しています。
NTP 設定
以下の要件で NTP 設定を行うこととします。
- NTP サーバとして以下2つを使用する
- 202.234.233.106
- 219.188.200.128
- 同期間隔は 30 分
- FortiGate を NTP サーバとして動作させない
■ Playbook:systemNTP.yml
- hosts: all
gather_facts: no
tasks:
- name: fortios_system_ntp test
fortios_system_ntp:
system_ntp:
ntpsync: "enable"
type: "custom"
ntpserver:
- id: "1"
server: "202.234.233.106"
- id: "2"
server: "219.188.200.128"
syncinterval: "30"
server_mode: "disable"
■ Playbook 実行
# ansible-playbook -i hosts systemNTP.yml
PLAY [all] **********************************************************************************************************
TASK [fortios_system_ntp 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 ntp
config system ntp
set ntpsync enable
set type fortiguard
set syncinterval 60
set source-ip 0.0.0.0
set source-ip6 ::
set server-mode disable
end
■ 実行後の FortiGate のコンフィグ
FGT # show full-configuration system ntp
config system ntp
set ntpsync enable
set type custom
set syncinterval 30
config ntpserver
edit 1
set server "202.234.233.106"
set ntpv3 disable
next
edit 2
set server "219.188.200.128"
set ntpv3 disable
next
end
set source-ip 0.0.0.0
set source-ip6 ::
set server-mode disable
end
Playbook で指定した通り NTP 設定が変更されました。
未解決問題
NTP サーバとして動作させる設定をしようとするとエラーとなりました。
■ Playbook:systemNTPSV.yml
- hosts: all
gather_facts: no
tasks:
- name: fortios_system_ntp test
fortios_system_ntp:
system_ntp:
server_mode: "enable"
interface:
- interface_name: "internal1"
■ 実行結果
# ansible-playbook -i hosts systemNTPSV.yml
PLAY [all] **********************************************************************************************************
TASK [fortios_system_ntp test] **************************************************************************************
fatal: [10.1.10.100]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "changed": false, "meta": {"build": 272, "http_method": "POST", "http_status": 405, "name": "ntp", "path": "system", "serial": "FGT60*************", "status": "error", "vdom": "root", "version": "v6.0.6"}, "msg": "Error in repo"}
PLAY RECAP **********************************************************************************************************
10.1.10.100 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
http_status が 405 なので、Playbook で指定したインターフェース名の間違いかと思いましたが internal1 の他 dmz や wan1 でも試しましたが同じ結果でした。
ちなみに手動で FortiGate に set server-mode enable と set interface “internal1” の設定を入れた状態で、以下の interface_name を何も指定しない Playbook を実行した場合はエラー無く実行できました。(interface_name を指定すると 405 エラーになりました。)
■ Playbook
- hosts: all
gather_facts: no
tasks:
- name: fortios_system_ntp test
fortios_system_ntp:
system_ntp:
server_mode: "enable"
interface:
■ 実行結果
# ansible-playbook -i hosts systemNTPSV.yml
PLAY [all] **********************************************************************************************************
TASK [fortios_system_ntp 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
上の結果から interface_name の指定に何らかの問題があると思われるのですが未解決です。
―――――――――――――