27.7. classify

The following documentation is for classify content package at version v4.1.2.

27.7.1. Classifier System

The Classifier System allows an operator flexibly define groups of “test/action” sequences to perform on a Machine. These can be used to do any number of tasks.

By default the classifier ships with a limited set of tests and actions that can be performed. However, the operator can specify additional groups of test/actions pairs by use of the classify/custom-functions Param. See the Param documentation on how to use it.

By default, the classifier is designed to exit on the first test match that succeeds with a “pass” status. The operator can override this behavior by setting the optional continue value set to true in the classify/classification-data structure.

If you are extending the Classifier to add custom groups of test/actions sequences, please review the function ... {} BASH functions in the classify.sh.tmpl template.

27.7.2. stages

The content package provides the following stages.

27.7.2.1. classify

Moves machines into new workflows based upon classification.

27.7.3. tasks

The content package provides the following tasks.

27.7.3.1. classify

This will change the machines workflow and add profiles.

27.7.4. params

The content package provides the following params.

27.7.4.1. classify/disable-classifier

In some use cases, you may need to disable the classifier system from running when machines are being provisioned. This parameter enables a fast disable, without having to remove the classifier itself.

Apply this Param with the value “true” to disable the classifier, on any machines or profiles applied to machines, to effect disabling.

For example, you could apply this Param to “global” profile to disable it globally. NOTE that normal precedence with Paramaters applies, so if a Machine has the Param applied also, the Machines Param value overrides the global value.

27.7.4.2. classify/classification-data

This object defines a series of tests to determine the classification of a Machine followed by a list of actions to apply to that Machine if the test is successful.

The order of precedence is important! A Machine will be evaluated in the order you specify in the tests below. Generally speaking, you should order the MOST SPECIFIC tests first, followed by general tests next. The very last test in the example below would be a default in the event no previous tests matched.

Setting “continue: true” in this Param data structure will allow the classifier to continue classifying after the first match. This effectively allows the operations to continue multiple tests/actions sequences, instead of exiting on first match.

If none of the tests match, then the Machine will not be modified.

The object should look like this.

  • test: “has_mac 00:11:22:33:44:55” continue: true actions: - “add_profile profile_name_1” - “change_workflow workflow_name_1”
  • test: “in_subnet 192.168.0.0/24” actions: - “set_parameter param_name value” - “add_profile profile_name_2” - “change_workflow workflow_name_2”
  • test: “always” actions: - “change_workflow wait-for-input”

In the above example, the “has_mac” test will be applied, if the test passes, it would normally exit the Classifier. However, the “continue” operator has been set to “true”, so the tests will continue to the next (“in_subnet”), and subsequently if passing that test, will apply the actions specified.

EXTENDING CLASSIFIER tests AND actions

The classifier can be extended to add custom “test” and “actions” groups. See the “classify/custom-functions” Param for details.

27.7.4.3. classify/custom-functions

Use this Param to specify additional custom templates to include in to the Classifier.

This is intended to inject BASH “function NAME { … }” stanzas in the classifer to provide custom function blocks to extend the tests and/or actions you can apply to the classifier.

# YAML example - “my-classify-function-1.tmpl” - “my-classify-function-2.tmpl”

# JSON example [

“my-classify-function-1.tmpl”, “my-classify-function-2.tmpl”

]

WARNING - The executing environment is Sledgehammer with BASH scripts. You
must insure that the Function you inject operates correctly in this environment. For reference, see the Functions in the existing classifier Template “classify.sh.tmpl”.

Any test functions should ‘echo “pass”’ or ‘echo “fail”’ to signal the test condition status and should subsequently apply the given actions specified.

An example template named “has_inventory_value.tmpl” has been provided that the operator can use as an example test condition.