main.yaml

Overview

main.yaml is an Ansible playbook designed to orchestrate the lifecycle management of the Block Keeper (BK) system components. It primarily handles tasks such as retrieving the epoch contract code hash, ensuring directory structures, copying configuration files, preparing the host environment, managing the Block Keeper service state (start, stop, upgrade), and performing cleanup operations (deleting data and logs). The playbook conditionally executes various included task files based on specific runtime flags and variables, enabling flexible deployment and maintenance workflows.

Structure and Functionality

The playbook consists of a sequence of named task entries, each executing either a direct Ansible module command or including other task files (include_tasks:). Execution of tasks is gated by conditional expressions (when:), allowing selective operation depending on the environment and desired actions.


Task Entries

1. Get Epoch code hash

- name: Get Epoch code hash
  ansible.builtin.set_fact:
    CODE_HASH: "{{ lookup('ansible.builtin.file', '../contracts/bksystem/BlockKeeperEpochContract.code.hash') }}"
  when: CODE_HASH is not defined

2. Ensure required directories exist


3. Copy static configs


4. Prepare host


5. Copy deployment configs


6. Pre-upgrade stop


7. Stop block keeper


8. Stop and delete data


9. Stop and delete logs


10. Ensure required directories exist after deleting something


11. Start block keeper


12. Bootstrap BK set


Important Implementation Details

Interactions with Other System Components

Visual Diagram

flowchart TD
A[Get Epoch code hash] --> B{DO_START and not FAST_UPDATE?}
B -->|Yes| C[Ensure required directories exist]
B -->|Yes| D[Copy static configs]
D --> E[Prepare host]
E --> F[Copy deployment configs]
F --> G{UPGRADE defined?}
G -->|Yes| H[Pre-upgrade stop]
I[DO_STOP?] --> J[Stop block keeper]
K[DELETE_DATA?] --> L[Stop and delete data]
M[DELETE_LOGS?] --> N[Stop and delete logs]
L & N --> O[Ensure required directories exist after delete]
P{DO_START or UPGRADE?} --> Q[Start block keeper]
R{BOOTSTRAP_BK_SET_URL and (DO_START or UPGRADE or DO_BOOTSTRAP)?} --> S[Bootstrap BK set]
B -->|No| T
I -->|No| T
K -->|No| T
M -->|No| T
G -->|No| T
P -->|No| T
R -->|No| T
style T fill:#f9f,stroke:#333,stroke-width:2px,color:#000

The diagram illustrates the conditional workflow of the playbook, showing how different tasks are executed based on input flags and variables. Tasks are connected in logical order reflecting dependencies and conditional branching.