fortinet-ansible-dev / ansible-galaxy-fortios-collection

GNU General Public License v3.0
85 stars 49 forks source link

Need help w/playbook to list all managed fortiap's per firewall. #297

Closed chr00ted closed 9 months ago

chr00ted commented 9 months ago

I’m trying to write a playbook to query all Fortinet’s and give me a list of all Access points managed by that device.

I’ve been going off: fortinet.fortios.fortios_monitor_fact module – Retrieve Facts of FortiOS Monitor Objects. — Ansible Documentation 1

But I’m not having too much luck. I’ve tried several iterations of the following playbook. The result it does give is listing (1) AP, but I know for a fact that the current host I’m testing off has several APs. My preferred output would show AP model as well as firmware version. Below is my test playbook and below that will be some debug output

https://docs.ansible.com/ansible/latest/collections/fortinet/fortios/fortios_monitor_fact_module.html 1

my code! hosts: all connection: httpapi gather_facts: no vars: vdom: “root” ansible_httpapi_use_ssl: yes ansible_httpapi_validate_certs: no ansible_httpapi_port: 443 ansible_network_os: fortinet.fortios.fortios tasks: name: Gather FortiAPs firmware list fortinet.fortios.fortios_monitor_fact: vdom: “root” selector: wifi_managed_ap debug: var: fortinet.fortios.fortios_monitor_fact Debug output: ok: [10.1.1.27] => { “changed”: false, “invocation”: { “module_args”: { “access_token”: null, “enable_log”: false, “filters”: null, “formatters”: null, “params”: null, “selector”: “wifi_managed_ap”, “selectors”: null, “sorters”: null, “vdom”: “root” } }, “meta”: { “action”: “”, “build”: 1575, “http_method”: “GET”, “name”: “managed_ap”, “path”: “wifi”, “results”: [ { “ap_profile”: “FAP222C New”, “ble_profile”: “”, “board_mac”: “90:6c:ac:39:04:4c”,

Any help would be greatly appreciated

MaxxLiu22 commented 9 months ago

Hi @chr00ted ,

Thank you for raising this question, your script looks good, in my environment, it just returned all AP information, could you try to collect AP information through GUI -> WIFI Controller -> Managed ForitAPs to see if all you wanted AP info is listed there since Ansible and GUI use the same API method to collect AP information, let me know if the GUI doesn't show the same info like Ansible.

  tasks:
  - name: Gather FortiAPs firmware list
    register: result
    fortios_monitor_fact:
      enable_log: true
      vdom: root
      selector: wifi_managed_ap
  - debug:
      msg: "{{ result.meta.results | json_query('[].{wtp_id: wtp_id, status: status}') }}"
PLAY [fortigates] ********************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************
ok: [fortigate03]

TASK [Gather FortiAPs firmware list] *************************************************************************************
ok: [fortigate03]

TASK [debug] *************************************************************************************************************
ok: [fortigate03] => {
    "msg": [
        {
            "status": "disconnected",
            "wtp_id": "FP231F****000001"
        },
        {
            "status": "disconnected",
            "wtp_id": "FP231F****000002"
        },
        {
            "status": "disconnected",
            "wtp_id": "FP231F****000003"
        }
    ]
}

PLAY RECAP ***************************************************************************************************************
fortigate03                : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Thanks, Maxx

chr00ted commented 9 months ago

Thanks @MaxxLiu22, I will retest and let you know.

chr00ted commented 9 months ago

Well, I'm having issues running in AWX with that as its calling for community.general in order run json.query. Trying to setup my requirements.yml to load both fortinet.fortios & community.general, but AWX complains if I have more than 1 collection. Troubleshooting that part now.

chr00ted commented 9 months ago

@MaxxLiu22 , thanks yet again. After I sorted out requirements.yml.

AWX did not like the requirements.yml looking like:

`--- collections:

The working requirements.yml looked like: `--- collections:

Thanks again @MaxxLiu22