Mandatory placement occurs any time the constraint's score is +INFINITY
or -INFINITY
. In such cases, if the constraint can't be satisfied, then the rsc resource is not permitted to run. For score=INFINITY
, this includes cases where the with-rsc resource is not active.
If you need resource1 to always run on the same machine as resource2, you would add the following constraint:
<rsc_colocation id="colocate" rsc="resource1" with-rsc="resource2" score="INFINITY"/>
Example 6.5. An example colocation constraint
Remember, because INFINITY
was used, if resource2 can't run on any of the cluster nodes (for whatever reason) then resource1 will not be allowed to run.
Alternatively, you may want the opposite... that resource1 cannot run on the same machine as resource2. In this case use score="-INFINITY"
<rsc_colocation id="anti-colocate" rsc="resource1" with-rsc="resource2" score="-INFINITY"/>
Example 6.6. An example anti-colocation constraint
Again, by specifying -INFINTY
, the constraint is binding. So if the only place left to run is where resource2 already is, then resource1 may not run anywhere.