fortinet-fortisoar / solution-pack-fortimanager-ztp-framework

MIT License
1 stars 3 forks source link

Change assignment search to set match to true if result != "" and False #17

Open ftnt-dspille opened 6 months ago

ftnt-dspille commented 6 months ago

https://github.com/fortinet-fortisoar/solution-pack-fortimanager-ztp-framework/blob/a986b3f0defa2419e956edb85c3f92620c5a23dc/playbooks/10%20-%20SP%20-%20FortiManager%20ZTP%20Flow%20-%20FortiManager(FMG)-RecordHandlers/_%20ztp%20profile%20assignment%20search.json#L40

The jinja here only checks if the result output of the jinja render is not equal to an empty string image

One thing i saw is that even if i am returning false from jinja, that the ztp profile was still matching it

{%- if record.sn == sheet.sn and sheet.cluster_member_id == "A" -%}
true
{%- else -%}
false
{%- endif -%}

devmeta

{
    "sheet": {
      "sn": "FGT80FTK23001037",
      "ap1_sn": "",
      "ap2_sn": "",
      "ap3_sn": "",
      "sw1_sn": "",
      "sw2_sn": "",
      "sw3_sn": "",
      "isp1_ip": "",
      "stack_id": 2,
      "nac_serial": "",
      "ap1_profile": "",
      "ap2_profile": "",
      "ap3_profile": "",
      "cluster_member_id": "B",
      "site_subnet_prefix": ""
    },
    "record": {
      "id": 104,
      "sn": "FGT80FTK23001037",
      "adom": "EMEA",
      "vdom": "root",
      "devname": "FortiGate-80F",
      "firmware": "7.2.7-build1577",
      "hostname": null,
      "platform": "FortiGate-80F",
      "meta_fields": {
        "Address": "",
        "Contact Email": "",
        "Company/Organization": "",
        "Contact Phone Number": ""
      },
      "connector_config": "FMG-OD"
    },
    "devmeta": {}
  }

image image

I have gotten the desired behavior working with

{%- set i = namespace(x=0) -%}
{%- set table = [] -%}
{%- for dev in vars.device_record_data -%}
  {%- set idx = {} -%}
  {%- if vars.steps.render_jinja[i.x].output not in ["", false] -%}
    {%- set ret = true -%}    
  {%- endif -%}
  {%- set _do = idx.update( {
      "ztp_profile_id":vars.ztp_profile_id,
      "id":dev.id,
      "matched": ret|default(false),
      "jinja_vars":vars.steps.get_jinja_vars[i.x].output,
      "jinja_search":vars.zprof_search
    } ) -%}
  {%- set _do = table.append(idx)  -%}
  {%- set i.x = i.x+1 -%}
{%- endfor -%}
{{table}}
fortijames commented 6 months ago

Added to the release 1.0.4 I'm currently working. https://github.com/fortijames/solution-pack-fortimanager-ztp-framework/commit/472402eed763de97baadb391eb0fb8f7ca8543e8 Thanks!!