The documentation doesn’t make it clear what order of operations is applied to host patterns. It gives an example:
webservers:dbservers:!phoenix:&staging
But in my testing using similar patterns, servers from phoenix might end up matching the pattern.
Here's the rules I've figured out.
1) ":&" is a lower priority than ":". In other words,
a:b:&c:d is (a:b)&(c:d). To match, the host must be in (a or b) and (c or d).
2) put your "!" rules at the back to ensure that those hosts are always excluded.
I had a pattern a:!b:&c:d. My host was in a, b & d, and matched the pattern, which surprised me. But if I changed it to a:&c:d:!b, it doesn't match. a:&d:c:!b also doesn't match.
I'm not sure how "!" is applied, but putting all "!" rules at the end of the pattern has worked for me so far.
thanks,
Bryan