Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions content/reference/promise-types/classes.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,60 @@ If an expression contains a mixture of different object types that need to be
ANDed together, this list form is more convenient than providing an
expression.

### cancel

**Description:** Undefine the promiser class when this string expression of
classes evaluates to true

Undefine the class on the left-hand side if the class expression on the
right-hand side evaluates to true. This is the inverse of
[`expression`][classes#expression]: where `expression` defines a class,
`cancel` removes one that is already defined.

The right-hand side is an ordinary class expression, so it may be a class name,
a compound expression, or the return value of a function that returns a class,
such as `fileexists()`.

Unlike the class-defining attributes, a `cancel` promise is evaluated **even
when the promiser class is already defined** — that is precisely when it has
work to do. If the cancel expression is true the class is undefined. If the
expression is false, or the class is not currently defined, the promise makes
no change. Reserved hard classes (such as `linux` or `cfengine`) cannot be
undefined and are left in place with a warning.

`cancel` is mutually exclusive with the class-defining attributes (`expression`,
`and`, `or`, `not`, `xor`, `dist`, `select_class`); combining it with any of
them is an `Irreconcilable constraints` error.

**Type:** `class`

**Allowed input range:** `[a-zA-Z0-9_!@@$|.()\[\]{}:]+`

**Example:**

```cf3 {skip TODO}
classes:

# Undefine 'maintenance' once the maintenance window has passed
"maintenance" cancel => "maintenance_window_over";

# Undefine 'have_config' if the file no longer exists
"have_config" cancel => not(fileexists("/etc/myapp.conf"));
```

**Notes:**

A class may be defined again later in the same agent execution (for example by
a class-defining promise evaluated in a later pass). `cancel` therefore does not
guarantee that a class stays undefined for the remainder of the run; it
undefines the class at the point the promise is evaluated.

**History:**

- Introduced in CFEngine 3.28.0.

**See also:** [`expression` classes attribute][classes#expression], [`cancel_kept`, `cancel_repaired` and `cancel_notkept` in classes body][Promise types#cancel_kept]

### dist

**Description:** Generate a probabilistic class distribution
Expand Down
Loading