Assign Service Rule failed with host.vars when structure differs

Hello Community,

I experience some problems with structed host.vars when trying to apply a service.

Example Host 1 and 2:

object Host "host1" {
    import "generic-agent"

    display_name = "host1"
    address = "10.10.246.94"
    zone = "virtual"
    vars.vendor = {
        virtual = {
            vmware = {
                vgpu = true
            }
        }
    }
object Host "host2" {
    import "generic-agent"

    display_name = "host2"
    address = "10.10.246.95"
    zone = "virtual"
    vars.vendor = {
        virtual = {
            vmware = true
        }
    }

When I try to assign a Server like this:

apply Service "Nvidia Grid Licence" {
    import "director_template"

    check_command = "nvidia_grid_licence"
    assign where host.vars.vendor.virtual.vmware.vgpu

    import DirectorOverrideTemplate
}

it fails because of:

critical/config: Error: Invalid field access (for value of type 'Boolean'): 'vgpu'

[stage]/zones.d/director-global/service_apply.conf(194): 
[stage]/zones.d/director-global/service_apply.conf(195):     check_command = "nvidia_grid_licence"
[stage]/zones.d/director-global/service_apply.conf(196):     assign where host.vars.vendor.virtual.vmware.vgpu
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[stage]/zones.d/director-global/service_apply.conf(197): 
[stage]/zones.d/director-global/service_apply.conf(198):     import DirectorOverrideTemplate

Context:

	(0) Evaluating 'apply' rule 
  (in [stage]/zones.d/director-global/service_apply.conf: 192:1-192:35)
	(1) Evaluating 'apply' rules for host 'host2'

I expected that if create an service apply rule inside Director with

host.vars.vendor.virtual.vmware.vgpu | is true (or set)

the evaluation will try to check if vgpu exists before it trys to check if vmware contains vgpu and its set or true.

Next I try to use the “contains” operator inside Director. Hoped that this will look if host.vars.vendor.virtual.vmware have an key or value with “vgpu”:

host.vars.vendor.virtual.vmware | contains | vgpu

This will fail also with critical error for both hosts:

critical/config: Error: Invalid right side argument for 'in' operator: true
Location: in [stage]/zones.d/director-global/service_apply.conf: 196:18-196:58
[stage]/zones.d/director-global/service_apply.conf(194): 
[stage]/zones.d/director-global/service_apply.conf(195):     check_command = "nvidia_grid_licence"
[stage]/zones.d/director-global/service_apply.conf(196):     assign where "vgpu" in host.vars.vendor.virtual.vmware
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[stage]/zones.d/director-global/service_apply.conf(197): 
[stage]/zones.d/director-global/service_apply.conf(198):     import DirectorOverrideTemplate

Context:

	(0) Evaluating 'apply' rule 
  (in [stage]/zones.d/director-global/service_apply.conf: 192:1-192:35)
	(1) Evaluating 'apply' rules for host 'host2'



critical/config: Error: Invalid right side argument for 'in' operator: {"vgpu":true}
Location: in [stage]/zones.d/director-global/service_apply.conf: 196:18-196:58
[stage]/zones.d/director-global/service_apply.conf(194): 
[stage]/zones.d/director-global/service_apply.conf(195):     check_command = "nvidia_grid_licence"
[stage]/zones.d/director-global/service_apply.conf(196):     assign where "vgpu" in host.vars.vendor.virtual.vmware
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[stage]/zones.d/director-global/service_apply.conf(197): 
[stage]/zones.d/director-global/service_apply.conf(198):     import DirectorOverrideTemplate

Context:

	(0) Evaluating 'apply' rule 
  (in [stage]/zones.d/director-global/service_apply.conf: 192:1-192:35)
	(1) Evaluating 'apply' rules for host 'host1'

I am not sure if this is a bug or this is behavior is wanted.
In case this is wanted, what could be a solution for this?

Thanks in advance.


  • Director version (System - About):1.9.0
  • Icinga Web 2 version and modules (System - About): 2.9.5
  • Icinga 2 version (icinga2 --version): 2.13.2-1
  • Operating System and version: RockyLinux 8
  • Webserver, PHP versions:
    • Apache 2.4.37-41
    • PHP 7.4.19

I hoped someone have tried to do something similar and are able to give me an example how to solve this.

What I am hoping, is to clear if the assign rule should critical fail when operator is boolen (vmware = true) and not dict (vmware = {vgpu = true}) when assigning assign where host.vars.vendor.virtual.vmware.vgpu

Hello @pbirokas!

It works as intended. If you access a field, e.g. host.vars.vendor.virtual.vmware.vgpu, your parent, host.vars.vendor.virtual.vmware, has to always be a container. {vgpu= true} is, but true isn’t. Replace the latter with {} to equalise the structures.

Best,
A/K