condition_from_expression_persistent
Create a new condition that persists across runs.
⚙️ 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. |
duration | The persistence suffix in minutes. This parameter is required. |
Outcome conditions
You need to replace ${condition}
with its actual canonified value.
- ✅ Ok:
condition_from_expression_persistent_${condition}_ok
- ☑️ Already compliant:
condition_from_expression_persistent_${condition}_kept
- 🟨 Repaired:
condition_from_expression_persistent_${condition}_repaired
- ☑️ Already compliant:
- ❌ Error:
condition_from_expression_persistent_${condition}_error
Example
method: condition_from_expression_persistent
params:
duration: VALUE
condition: VALUE
expression: VALUE
Documentation
This method evaluates an expression (=condition combination), and produces a ${condition}_true
or a ${condition}_false
condition depending on the result on the expression,
which will lasts for the Duration time:
- This method always result with a success outcome status
- If the expression evaluation results in a "defined" state, this will define a
${condition}_true
condition, - If the expression 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 class condition.
The created condition is global to the agent and is persisted across runs. The persistence duration is controlled using the parameter Duration which defines for how long the target condition will be defined (in minutes). Note that there is no way to persist indefinitely.
Example:
If you want to check if a condition evaluates to true, like checking that you are on Monday, 2am, on RedHat systems, and make it last one hour you can use the following policy
condition_from_expression_persistent_("backup_time", "Monday.redhat.Hr02", "60")
The method will define:
- In any case:
condition_from_expression_persistent_backup_time_kept
condition_from_expression_persistent_backup_time_reached
- And:
backup_time_true
if the system is a RedHat like system, on Monday, at 2am, and will persist for Duration minutes,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.