Blocks that define variables (values other blocks can use) and classes (conditions other blocks can depend on).

Define Class

Defines one or more classes from conditions, for other blocks to use.

Generates: a classes promise.

Settings

Setting Required Description
Class name Yes Letters, numbers, and underscores only — and not the name of a built-in class like linux.

Sources

Where the class comes from:

Source CFEngine Settings
Always true any —
Always false !any —
All of these classes (AND) and => —
Any of these classes (OR) or => —
File exists fileexists() File path
Directory exists isdir() Directory path
Variable is defined isvariable() Variable name
Value matches pattern (regex) regcmp() Pattern (regex), Value to match
Values are equal strcmp() First value, Second value
Value is greater than isgreaterthan() Value, Is greater than
Value is less than islessthan() Value, Is less than
Command succeeds returnszero() Command, Shell mode
Custom expression — Condition expression

Example

The policy it generates, for example:

classes:
  # Roles
  "nginx_installed" expression => fileexists("/usr/sbin/nginx");

Define Variable

Defines one or more variables other blocks can reference.

Generates: a vars promise.

Settings

Setting Required Description
Variable name Yes Letters, numbers, and underscores only.

Sources

Where the variable comes from:

Source CFEngine Settings
Literal string Value
List slist Items
Per condition ifelse() Values, Otherwise
Structured data (literal) parsejson() JSON
Variable $(…) Variable
List variable @(…) List variable
Data variable mergedata() Data variable
Command output execresult() Command, Shell mode, Capture
File lines readstringlist() File path, Skip lines matching, Split on (regex), Max entries, Max bytes
File content readfile() File path, Max bytes
File metadata filestat() File path, Attribute
Environment variable getenv() Environment variable name, Max characters
Structured data (JSON) readjson() File path, Max bytes

Example

The policy it generates, for example:

vars:
  # App settings
  "app_port" string => "8080";
  "admins" slist => { "alice", "bob" };