Director - Assign Where & Operators (I'm confused)

I could use some education here. I am very confused by the assign where operators page. Particularly in the service set area.

Can someone explain how it works in director? Every time I think I understand it, I don’t.

For example: If I want to assign where = sql AND NOT = somesqlserver

Some examples:
assign where == "ST-IDOIT-RZ" || match("ST-MON-MAS*-RZ", || == "ST-OPS-MON-SAT-RZ" || == "ST-MON-SAT-FR" || == "ST-MYSQL1-RZ"

assign where != "this" && != "that" && != "ST-GRAFANA-RZ" && ( == "cpu" || == "load" || == "memory" || == "swap")

Your example would be
assign where == "sql" && != "somesqlserver"

Once you have some experience setting up those assign rules it gets easier.
You can combine multiple layers of concatenations under one “root” operand and then get crazy :wink:


Thank you! I will play around with it some more.

I think the most important piece of info you have to keep in mind is that the operand on top of the indented block is the one that connects all conditions on that level.

Each new level of indentation can be seen as a logical block of conditions - evaluated by applying the operand above between all of them.

This sounds a bit confusing but is actually simple and it helps (at least me) to read the conditions in blocks. Then you can get crazy about it as @log1c already said.

But, at the same time, don’t hesitate to make a step back and review the logic of your service or host vars for example if you find yourself with real complex assignment rules. This might be an indicator that you should simplify the host or service configuration and make your life easier.


The last example you gave that fits my example does not seem to work.

AND = hostname1 = hostname2 != hostname3

It doesn’t apply to anything if I set it this way. Removing the != hostname3 allows the service to apply to hostname1 and hostname2

You need another OR for combining hostname1 and hostname2

assign where ( == "hostname1" || == "hostname2") && != "hostname3"

Adding a “sublevel” operator is done via the >> button

Tbh I’m surprised that == "hostname1" && == "hostname2" works.
Imo this should not work, because you don’t have a host object that has both names. Or am I just thinking false about the condition?

1 Like

I’m still not getting it. Would you mind sending a screenshot of the entire condition set of a working one where the service applies to hostname1 and hostname2 but not hostname3?


This way you have the “root” condition set to AND, which “splits” the assignment rule into two parts:

Part1 = ( == “hostname1” || == “hostname2”)
Part2 = != "hostname3"

Due to the AND this means that both sides of the condition have to be true.
This is the case when the hostname is either hostname1 OR hostname2 while it must not be hostname3

1 Like

That did it. I think I am starting to understand. Maybe it is just the way the interface works that is throwing me off.

Thank you!