condition_from_expression

Create a new condition.

⚙️ Compatible targets: Linux

Parameters

NameDocumentation
conditionThe condition prefix.

This parameter is required.
expressionThe expression evaluated to create the condition (use 'any' to always evaluate to true).

This parameter is required.

Outcome conditions

You need to replace ${condition} with its actual canonified value.

  • ✅ Ok: condition_from_expression_${condition}_ok
    • ☑️ Already compliant: condition_from_expression_${condition}_kept
    • 🟨 Repaired: condition_from_expression_${condition}_repaired
  • ❌ Error: condition_from_expression_${condition}_error

Example

method: condition_from_expression
params:
  expression: VALUE
  condition: VALUE

Documentation

This method evaluates an expression, and produces a ${condition}_true or a ${condition}_false condition depending on the result of the expression evaluation:

  • This method always result with a success outcome status
  • If the evaluation results in a "defined" state, this will define a ${condition}_true condition,
  • If the evaluation results in an "undefined" state, this will produce a ${condition}_false condition.

Calling this method with a condition expression transforms a complex expression into a single condition.

The created condition is global to the agent.

Example

If you want to check if a condition evaluates to true, like checking that you are on Monday, 2am, on RedHat systems, you can use the following policy

condition_from_expression("backup_time", "Monday.redhat.Hr02")

The method will define:

  • In any case:
    • condition_from_expression_backup_time_kept
    • condition_from_expression_backup_time_reached
  • And:
    • backup_time_true if the system is a RedHat like system, on Monday, at 2am.
    • backup_time_false if the system not a RedHat like system, or it's not Monday, or it's not 2am
    • no extra condition if the expression is invalid (cannot be parsed)
Notes:

Rudder will automatically "canonify" the given Condition prefix at execution time, which means that all non [a-zA-Z0-9_] characters will be replaced by an underscore.