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 host.name = sql AND NOT host.name = somesqlserver

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

assign where host.vars.site != "this" && host.vars.site != "that" && host.name != "ST-GRAFANA-RZ" && (service.name == "cpu" || service.name == "load" || service.name == "memory" || service.name == "swap")
image

Your example would be
assign where host.name == "sql" && host.name != "somesqlserver"
image

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:

4 Likes

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.

2 Likes

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

AND
host.name = hostname1
host.name = hostname2
host.name != 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 (host.name == "hostname1" || host.name == "hostname2") && host.name != "hostname3"

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

Tbh I’m surprised that host.name == "hostname1" && host.name == "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?

image

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

Part1 = (host.name == “hostname1” || host.name == “hostname2”)
&&
Part2 = host.name != "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!