Skip to main content

Playbook

Playbooks are configurable automated processes that can be used to perform a variety of actions for a component or a config item. They are defined using a YAML configuration.

restart-unhealthy-database.yaml
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: restart-unhealthy-database
spec:
description: Restart when a database becomes unhealthy
on:
component:
- event: unhealthy
filter: component.type == 'database'
labels:
industry: e-commerce
actions:
- name: 'Restart kubernetes deployment'
exec:
script: kubectl rollout restart deployment {{.component.name}}

Playbooks List Fig: Playbooks Page

Spec

FieldDescriptionSchemeRequired
descriptionA short descriptionstringtrue
iconIcon for the playbookstring
onSpecify events to automatically trigger the Playbook. .[]Trigger
checksSpecify selectors for checks that can be run on the Playbook.[]ResourceFilter
configsSpecify selectors for config items that can be run on the Playbook.[]ResourceFilter
componentsSpecify selectors for component items that can be run on the Playbook.[]ResourceFilter
parametersDefine a set of labeled parameters for the Playbook.[]Parameter
actionsSpecify the set of actions to run.[]Actiontrue
approvalSpecify who can approve runs on this playbook.Approval

Trigger

FieldDescriptionSchemeRequired
canarySetup trigger on canary eventsEventTrigger
componentSetup trigger on health check events.EventTrigger
webhookSetup a webhook endpoint that triggers the playbook.WebhookTrigger

ResourceFilter

Filters can define what resources (checks, configs or components) are permitted be run on the Playbook.

FieldDescriptionSchemeRequired
typeSpecify type of component.string
tagsSpecify tags of component.map[string]string

Parameter

Playbook parameter defines a parameter that a playbook needs to run.

FieldDescriptionSchemeRequired
nameName of parameter.stringtrue
defaultDefault value of the parameter.string
labelLabel of the parameter.stringtrue
requiredSpecify if the parameter is requiredbool
iconIcon of parameter. See iconsstring
descriptionDescription of the parameter.string
typeType of parameter.string
propertiesProperties of parameter.map[string]string

Run

A run is the execution of a Playbook consisting of a sequence of actions. A run can be trigger either

  • manually
  • on events
  • on schedule (upcoming)

For example, a playbook can be executed when a health check passes or fails.

Playbook Runs Fig: Playbooks Runs

Start Time

Every run must have a start time which is the time the run is scheduled to start. By default, the it is set to the current time.

Start time can be in future or even in the past.

Action

Actions are the fundamental tasks executed by a playbook. A playbook can comprise multiple actions, which are executed sequentially. If any action encounters an error and fails, the execution of the playbook is halted.

FieldDescriptionSchemeRequired
nameName of action.stringtrue
delayA CEL expression that evaluates to a duration to delay the execution of the action. (Sensitive to the minute.)string
timeoutTimeout on this action.DurationString
execSpecify exec of action.ExecAction
gitopsSpecify gitops of action.GitopsAction
httpSpecify http of action.HttpAction
sqlSpecify sql of action.SqlAction
podSpecify pod of action.PodAction
notificationSpecify notification of action.NotificationAction
note

Specify one or more actions; but at least one.

Playbook Action Logs Fig: Playbooks Action Logs

Delaying actions

Actions can be delayed by a fixed duration or conditionally by a CEL expression. It's only sensitive to the minute. i.e. if you delay by 20s it can take upto a minute to execute.

Templating

The CEL expression receives a environment variable that contain details about the corresponding config, check or component and the parameter (if applicable).

FieldDescriptionSchema
configConfig passed to the playbookConfigItem
componentComponent passed to the playbookComponent
checkCanary Check passed to the playbookCheck
paramsUser provided parameters to the playbookmap[string]string

Valid time units are "s", "m", "h", "d", "w", "y". Eg:

  • 1m15s
  • 1h5m
  • 23h
  • 1d8h
  • 1w6d8h
  • 19w0d8h

Conditionally running actions

Playbook actions can be conditionally run using a CEL Expression. The expressions should either return

  • a boolean value (true indicating run the action & skip the action otherwise)
  • or a special function among the ones listed below

Functions

FunctionDescription
always()run no matter what; even if the playbook is cancelled/fails
failure()run if any of the previous actions failed
skip()skip running this action
success()run only if all previous actions succeeded (default)
timeout()run only if any of the previous actions timed out

Examples

  • if: config.deleted_at ? true: false
  • if: always()