Icinga / ansible-collection-icinga

Collection to setup and manage components of the Icinga software stack
Apache License 2.0
46 stars 35 forks source link

Bug when using `value` or `key` variable #344

Open lucagubler opened 2 weeks ago

lucagubler commented 2 weeks ago

There's a bug when using the value or key variable in combination with apply_for loops. I want to loop over a dictionary or list and then use the key or value to access items.

Here's an example service

...
  - name: Check BGP VRF- + value.description
    type: Service
    display_name: Check BGP VRF- + value.description
    file: zones.d/main/services/services.conf
    apply: true
    apply_for: key => value in host.vars.nb.config.bgp_sessions.vrf
    imports:
      - generic-service
    check_command: check_nwc_health
    assign:
      - host.vars.nb.platform == slx-os
    vars:
      check_nwc_mode: bgp-peer-status
      snmp_v3_context: key
...

here's the rendered Icinga2 object. Please note the quotes around value.description.

apply Service for (key => value in host.vars.nb.config.bgp_sessions.vrf)  {
  import "generic-service"

  display_name = "Check BGP VRF-" + "value.description"
  check_command = "check_nwc_health"
  assign where host.vars.nb.platform == "slx-os"
  vars.check_nwc_mode = "bgp-peer-status"
  vars.snmp_v3_context = key
}

These quotes need to be removed so that the GUI correctly displays the monitored services.