Skip to content

[Question] How to implement contains in hostgroup assign where clause #273

@lutin-malin

Description

@lutin-malin

Question

Hello,

I'm trying to replicate a manually made hostgroup configuration like below :

Image

using the icinga_hostgroup module.

I've tried two notations, 'contains' and 'in' and none is rendering properly.

contains notation :

- name:  Icinga configure hostgroups
  telekom_mms.icinga_director.icinga_hostgroup:
    object_name: custom_hostgroup
    assign_filter: 'host.vars.custom_field contains "my_var_value"'

Deployment fails

[2025-03-07 11:04:43 +0100] critical/config: Error: syntax error, unexpected T_IDENTIFIER, expecting '}'
Location: in [[stage]/zones.d/director-global/hostgroups.conf]: 30:35-30:42
[[stage]/zones.d/director-global/hostgroups.conf]: object HostGroup "custom_hostgroup" {
[[stage]/zones.d/director-global/hostgroups.conf]:     assign where host.vars.custom_field  contains my_var_value == 1
                                                                                                                                             ^^^^^^^^

we can see that the assign criteria is suffixed with == 1, which is obviously invalid

note : playing with postman targeting directly the director API, i can confirm that submitting the contains syntax as above is converted by the API itself to var contains value == 1, so issue should not be related to the ansible module icinga_hostgroup

in notation

- name:  Icinga configure hostgroups
  telekom_mms.icinga_director.icinga_hostgroup:
    object_name: custom_hostgroup
    assign_filter: '"my_var_value" in host.vars.custom_field'

which ends up in
` assign where null in 1``

[2025-03-06 18:29:23 +0100] critical/config: Error: Invalid right side argument for 'in' operator: 1
Location: in [[stage]/zones.d/director-global/hostgroups.conf: 30:18-30:26
[[stage]/zones.d/director-global/hostgroups.conf]: 
[[stage]/zones.d/director-global/hostgroups.conf]: object HostGroup "custom_hostgroup" {
[[stage]/zones.d/director-global/hostgroups.conf]:     assign where null in 1
                                                                                                 ^^^^^^^^^

Could you help me to achieve the proper assign where clause ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions