Closed nklerk closed 8 months ago
Hi @nklerk ,
Thank you for raising this issue, I will report it to development team for further investigation. From the error msg, that wants you to provide access token to access FGT. My suggestion is create a API user and generate an access token on FGT, then use this token to access FGT via Ansible,
- name: Grab facts
hosts: all
gather_facts: no
connection: httpapi
collections:
- fortinet.fortios
vars:
ansible_httpapi_use_ssl: yes
ansible_httpapi_validate_certs: no
ansible_httpapi_port: 443
ansible_user: "admin"
ansible_ssh_pass: "*************"
vdom: "root"
ansible_network_os: fortinet.fortios.fortios
tasks:
- name: Print ansible user and pw defaulting to None to avoid undefined error
debug:
msg: "USER: {{ ansible_user | default(None) }}, PW: {{ ansible_password | default(None) }}"
- name: Get multiple selectors info concurrently
fortios_configuration_fact:
access_token: "xx737Q94bh5tw0qhQhtQngmdf8xtGy" // generated by FGT in advance
selectors:
- selector: system_global
register: fortifacts
this code works well on my ansible 6.2.0
Thanks, Maxx
or you can change "ansible_ssh_pass" to "ansible_password", that would also work.
- name: Grab facts
hosts: all
gather_facts: no
connection: httpapi
collections:
- fortinet.fortios
vars:
ansible_httpapi_use_ssl: yes
ansible_httpapi_validate_certs: no
ansible_httpapi_port: 443
ansible_user: "admin"
ansible_password: "psw"
vdom: "root"
ansible_network_os: fortinet.fortios.fortios
tasks:
- name: Print ansible user and pw defaulting to None to avoid undefined error
debug:
msg: "USER: {{ ansible_user | default(None) }}, PW: {{ ansible_password | default(None) }}"
- name: Get multiple selectors info concurrently
fortios_configuration_fact:
selectors:
- selector: system_global
register: fortifacts
Thanks, Maxx
Hi @nklerk,
The error indicates that you need to provide a valid access_token or username/password to log into the fortigate device. We highly recommend using access_token to log into a fortigate device. Maxx has provided an example.
I wonder which collection version you used when using Ansible 5. Did you still use fortiOS Collection 2.1.7?
Thanks, Jie
Hi @nklerk
I will close this issue as it's been a while and no further updates or responses have been received, indicating that the matter has likely been resolved or is no longer active. If you have any further questions or concerns, please feel free to reopen the ticket or create a new one.
After upgrading Ansible to 6.3.0 the fortinet.fortios can't connect to the fortigate API. I tested the following playbook to work on Ansible 5.7.1 and 5.10.0. and not to work on 6.0.0, 6.1.0 and 6.2.0
Collection version(s):
The playbook I use to test with.
Error message on task2:
Versions working: