condition_from_expression
Create a new condition.
⚙️ Compatible targets: Linux
Parameters
| Name | Documentation |
|---|---|
| condition | The condition prefix. This parameter is required. |
| expression | The 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
- ☑️ Already compliant:
- ❌ Error:
condition_from_expression_${condition}_error
Example
method: condition_from_expression
params:
condition: VALUE
expression: 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}_truecondition, - If the evaluation results in an "undefined" state, this will produce a
${condition}_falsecondition.
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_keptcondition_from_expression_backup_time_reached
- And:
backup_time_trueif the system is a RedHat like system, on Monday, at 2am.backup_time_falseif 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.