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

GNU General Public License v3.0
84 stars 47 forks source link

fortinet.fortios.fortios_monitor_fact filter questions #295

Closed chr00ted closed 5 months ago

chr00ted commented 5 months ago

First off, thank you for the fortios collection, very much appreciated. I'm using the fortinet.fortios.fortios_monitor_fact and I'm trying to give me the hostname of the firewall and set the hostname as a fact. How can I go about that. The only time I see any information is when I turn on debug.

Using your formatters and filter example:

With that filter, I would only expect to see: Ansible return the model_Name Fortigate. Am I wrong in thinking that is what you filter puts out? My real question is how can I gather the hostname only and set that as a fact.

ok: [172.16.100.101] => { "changed": false, "invocation": { "module_args": { "access_token": null, "enable_log": false, "filters": [ "model_name==FortiGate" ], "formatters": [ "model_name" ], "params": null, "selector": "system_status", "selectors": null, "sorters": null, "vdom": "root" } }, "meta": { "action": "", "build": 1577, "http_method": "GET", "name": "status", "path": "system", "results": { "hostname": "Testing-100F", …

MaxxLiu22 commented 5 months ago

Hi @chr00ted ,

Thank you for raising this question, formatters and filters are not used for all resources, the example is kind of confusing, sorry about that. Here is an example for your reference, let me know if that doesn't solve your question.

- hosts: fortigates 
  collections:
  - fortinet.fortios
  connection: httpapi
  vars:
    vdom: root
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_httpapi_port: 443
  tasks:
   -  name: Get system status
      register: result
      fortinet.fortios.fortios_monitor_fact:
        vdom: root
        selector: 'system_status'
   - debug: msg="{{ result.meta.results.hostname }}"
running resulte
PLAY [fortigates] ******************************************************************************************************************************************************************************************

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

TASK [Get system status] ***********************************************************************************************************************************************************************************
ok: [fortigate03]

TASK [debug] ***********************************************************************************************************************************************************************************************
ok: [fortigate03] => {
    "msg": "FGVMULTM23002230"
}

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

Thanks, Maxx

chr00ted commented 5 months ago

@MaxxLiu22 - Thank you so much, that was exactly what I needed!

I have posted Fortinet playbook specific questions under Ansible Community forum for a separate issue. Would it be better to post Fortinet specific questions here or there or both? I don't want to bother you all.

MaxxLiu22 commented 5 months ago

Hi @chr00ted ,

You are welcome to post any questions here to let us know your concerns.

Thanks, Maxx

chr00ted commented 5 months ago

Thanks again for all of your help @MaxxLiu22