9.6 Resource templates
9.6.1 Configuring resources with templates
If you want to create lots of resources with similar configurations, defining a resource template simplifies the task. Once defined, it can be referenced in primitives. The primitives referencing the template will inherit all meta attributes , instance attributes, utilization attributes and operations defined in the template. And you can define specific attributes and operations for any of the primitives. If any of these are defined in both the template and the primitive, the values defined in the primitive will take precedence over the ones defined in the template.
Hence, it helps reduce the size of configuration. And users can globally modify definitions of resources from a template easily.
Resource template has the similar syntax with primitive. For example:
Example of a resource template:
Once you defined the new resource template, you can use it in primitives:
Example of a primitive referencing a resource template:
The new primitive vm1 is going to inherit everything from the vm-template. For example, the equivalent of the above two would be:
If you want to overwrite some attributes or operations, add them to the particular primitive's definition.
For instance, the following new primitive vm2 has special attribute values. Its monitor operation has longer timeout and interval. And it has an additional stop operation.
The following command shows the resulting definition of a resource:
crm_resource --query-xml --resource vm2
The following command shows its raw definition in cib:
crm_resource --query-xml-raw --resource vm2
9.6.2 Referencing templates in constraints
A resource template can be referenced in the following types of constraints:
- order constraints,
- colocation constraints,
- rsc_ticket constraints (for multi-site clusters).
Resource templates referenced in constraints stand for all primitives which are derived from that template. This means, the constraint applies to all primitive resources referencing the resource template. Referencing resource templates in constraints is an alternative to resource sets and can simplify the cluster configuration considerably.
For example:
It is the equivalent of:
Note: In a colocation constraint, only one template may be referenced from either "rsc" or "with-rsc", and the other reference must be a regular resource.