Notes by Doctor Droid

What is Context Propagation in Playbooks?

·

2 min read

This blog dives into the concept of context propagation, starting with an understanding of variables in Playbooks.

Cover Image for What is Context Propagation in Playbooks?

Variables can be configured in any queries or related fields in a playbook task, and their values can be changed in real time during execution from the web or via workflows. This flexibility allows playbooks to be reused for similar services or components.

Playbook Example

Step 1: Consider a Kubernetes playbook with a task to get all the pods and their status from a namespace.

Step 2: The playbook also includes a task to get all the logs for the pods using Kubectl command.

Step 3: The Kubectl command is configured with a variable called namespace.

Step 4: Similarly, there's a Kubectl command to get logs for the pods and the namespace.

Step 5: Execute the playbook to get all the pods for the namespace deployment.

Context Propagation

Step 1: While configuring a playbook task, inject the context from the result of a task into a variable.

Step 2: For instance, the pods that are coming for the names is deployment, and then apply a transformer function on the output of this task to get all the pods from the output in real time.

Step 3: Test this code to get all the pods that have resulted as the output of this task.

Step 4: Run this task with this transformer applied on top of it, it will update the pods value which further will be used in the execution of the next task.

Context Injection via Workflows

Step 1: The context in these variables can also be injected via workflows.

Step 2: For example, a workflow gets triggered by a slack alert which contains a context of which namespace this alert is coming from.

Step 3: Apply a transformer that will read that slack alert to extract the namespace and inject that into the variable in the playbook.

Step 4: The namespace variable in the playbook gets updated.

Step 5: Send a notification of the alert coming in the Slack channel to trigger the workflow.

Step 6: The transformer configured in the workflow will extract the namespace, which will be available in the playbook execution of that workflow. As seen, all the pods for the namespace datadog are retrieved, and then further all the logs that were, that are, that came as the result of the previous task are obtained.