Assigning Hostgroups during Director synchronisation

Hi there,

I want to assign my Hostgroups, that I import from SQL to my hosts where the group is located in an array “ host.vars.roles ”.

Normally this works like
assign where "webserver" in host.vars.roles

However I do not see any possibility to do this in Director when doing synchonisation. When I try to do it “as i would do it via files”, its wrong

If somewone could point me to a proper documentation how I can make the needed assign rule above working, it would be very helpfull :slight_smile:
Thanks and regards


You can’t do that in sync rules (afaik), because the sync rule does not know about the hosts variables.
You can only use information from import sources.

So to assign the host group to different hosts the assign rule for the hostgroup that uses the host.vars.roles is the way to go.

Hello log1c,

i do not agree here. The vars do not have to be evaluated at this moment. Its a simple assign rule statement that has just to be written into the object config as it is.

best regards

I’m not quite sure I understood what exactly you want.

I am pretty sure(99%) that you can not create assign filter statements from an import and sync.

Do you want to add hostgroups to a host?
Or do you want to add hostgroups to the config from an import&sync?

Hello Ralf,

the solution: go to your Sync Rule -> Properties

You must define the assign rule in a custom expression. The syntax is not the
same as you know of the Object-Type in Icinga2.

“${name}”=host.vars.roles => assign where <$name> in host.vars.roles

follow the link to learn more about the expressions.

best regards


Nice, absolutely did not know about that. No wonder if it is not mentioned anywhere in the docs.

@theFeu pinging you, as there is essential information missing from the docs for a function the Director provides for at least three years. Could that be merged into the official docs?


Well, I have to say that I personally am not that familiar with the director and didn’t know about that myself.

I will have to look into that (both the official documentation and what is described here) and figure out which colleague might be most suited to tackle that.

Some cooperation will be needed here and, as it is holiday season and the first person that came to mind is unavailable right now, this might take a little while.

Thank you for pointing it out though!

Thank you all for your hints. However I wonder why this assign rules in director sync are different (and less understandable) syntax as configured via files.