作業環境
■ Ansible 側
- CentOS 8.0
- Python 3.7.7
- Ansible 2.9.6
■ FortiGate 側
- 型番:FortiGate 60E
- ファームウェアバージョン:v6.0.6 build0272 (GA)
fortios_facts モジュール
fortios_facts モジュールを使用することで FortiGate のシステム情報(Facts)を取得できます。
主なパラメータ
パラメータ | 必須 | 選択肢/デフォルト | 説明 |
gather_subset | ● | 下記の fact と filters を子要素として持つ | |
– fact | ● | 下記備考参照 | gather_subset の子要素 収集対象 fact 名 |
– filters | gather_subset の子要素 facts 収集時に適用するフィルタ | ||
host | 対象機器のIPアドレス | ||
username | SSH用のユーザ | ||
password | ・”” ← | SSH用のパスワード | |
vdom | ・root ← | 対象機器のバーチャルドメイン | |
https | ・no ・yes ← | HTTPSを使用するかどうか | |
ssl_verify | ・no ← ・yes | 対象機器の証明書を検証するかどうか |
備考
- Legacy モードと httpapi の両方がサポートされている
- Legacy モードでの実行のためには fortiosapi が必要
- host、username、password を指定すると Legacy モードでの実行になる
- fact パラメータの選択肢
- system_current-admins_select
- system_firmware_select
- system_fortimanager_status
- system_ha-checksums_select
- system_interface_select
- system_status_select
- system_time_select
使用例
■ ディレクトリ構成
.
|-- group_vars
| `-- forti.yml
|-- hosts
|-- legacy.yml
`-- httpapi.yml
■ インベントリ:hosts
[forti]
10.1.10.100
10.1.10.100 は操作対象の FortiGate のIPアドレスです。
■ group_vars/forti.yml
ansible_user: admin
ansible_password: password
ansible_network_os: fortios
ansible_connection: httpapi
ansible_httpapi_use_ssl: yes
ansible_httpapi_validate_certs: no
forti.yml で httpapi で使用する変数をグループ変数として定義しています。
Legacy モードの場合
■ Playbook:legacy.yml
- hosts: localhost
gather_facts: no
tasks:
- name: Get fortios_facts
fortios_facts:
host: 10.1.10.100
username: admin
password: password
vdom: root
https: yes
ssl_verify: no
gather_subset:
- fact: system_status_select
register: fortios_facts_result
- name: system_status_select
debug:
var: fortios_facts_result
Legacy モードの場合は、hosts: で localhost を指定します。
■ 実行結果
# ansible-playbook -i hosts legacy.yml
PLAY [localhost] ****************************************************************************************************
TASK [Get fortios_facts] ********************************************************************************************
ok: [localhost]
TASK [system_status_select] *****************************************************************************************
ok: [localhost] => {
"fortios_facts_result": {
"ansible_facts": {
"ansible_net_gather_network_resources": [],
"ansible_net_gather_subset": [],
"ansible_network_resources": {
"system_status_select": {
"action": "select",
"build": 272,
"http_method": "GET",
"name": "status",
"path": "system",
"results": {},
"serial": "FGT*************",
"status": "success",
"vdom": "root",
"version": "v6.0.6"
}
}
},
"changed": false,
"failed": false
}
}
PLAY RECAP **********************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
httpapi の場合
■ Playbook:httpapi.yml
- hosts: all
gather_facts: no
tasks:
- name: Get fortios_facts
fortios_facts:
vdom: root
gather_subset:
- fact: system_status_select
register: fortios_facts_result
- name: system_status_select
debug:
var: fortios_facts_result
httpapi を使用する場合は、hosts: で対象の FortiGate を指定します。
■ 実行結果
# ansible-playbook -i hosts httpapi.yml
PLAY [all] **********************************************************************************************************
TASK [Get fortios_facts] ********************************************************************************************
ok: [10.1.10.100]
TASK [system_status_select] *****************************************************************************************
ok: [10.1.10.100] => {
"fortios_facts_result": {
"ansible_facts": {
"ansible_net_gather_network_resources": [],
"ansible_net_gather_subset": [],
"ansible_network_resources": {
"system_status_select": {
"action": "select",
"build": 272,
"http_method": "GET",
"name": "status",
"path": "system",
"results": {},
"serial": "FGT*************",
"status": "success",
"vdom": "root",
"version": "v6.0.6"
}
},
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"failed": false
}
}
PLAY RECAP **********************************************************************************************************
10.1.10.100 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
参考ページ
―――――――――――――