Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

runbook

> DevOps
Open source

A framework for gradual system automation

768 stars0 likes0 views
WebsiteGitHub

About

A framework for gradual system automation

Runbook

See our blog post for the philosophy behind Runbook and an overview of its features.

Runbook provides a DSL for specifying a series of steps to execute an operation. Once your runbook is specified, you can use it to generate a formatted representation of the book or to execute the runbook interactively. For example, you can export your runbook to markdown or use the same runbook to execute commands on remote servers.

Runbook has two modes for evaluating your runbook. The first mode, view mode, allows you to export your runbook into various formats such as markdown. The second mode, run mode, allows you to execute behavior based on the statements in your runbook.

Runbook can be integrated into existing infrastructure in many different ways. It can be integrated into existing projects to add orchestration functionality, installed on systems as a stand-alone executable, or runbooks can be defined as self-executable scripts. In addition to being useful for automating common tasks, runbooks are a perfect bridge for providing operations teams with step-by-step instructions to handle common issues (especially when solutions cannot be easily automated).

Lastly, Runbook provides an extendable interface for augmenting the DSL and defining your own behavior.

Features

  • Remote Command Execution - Runbook lets you execute commands on remote hosts using SSHKit
  • Dynamic Control Flow - Runbooks can start execution at any step and can skip steps based on user input.
  • Resumable - Runbooks save their state at each step. If your runbook encounters an error, you can resume your runbook at the previous step after addressing the error.
  • Noop and Auto Modes - Runbooks can be executed in noop mode. This allows you to see what a runbook will do before it executes. Runbooks can be run in auto mode to eliminate the need for human interaction.
  • Execution Lifecycle Hooks - Runbook provides before, after, and around hooks to augment its execution behavior.
  • Tmux Integration - Runbook integrates with tmux. You can define terminal pane layouts and send commands to terminal panes.
  • Generators - Runbook provides commands to generate runbooks, extensions, and runbook projects. You can define your own generators for easy, customized runbook creation.
  • Extendable DSL - Runbook's DSL is designed to be extendable. You can extend its DSL to add your own behavior.

Use Cases

Though Runbook can solve a myriad of problems, it is best used for removing the need for repeated, rote developer operations. Runbook allows developers to execute processes at a higher level than that of individual command-line commands. Additionally, Runbook provides features to simply and safely execute operations in mission-critical environments.

Runbook is not intended to replace more special-purpose automation solutions such as configuration management solutions (Puppet, Chef, Ansible, Salt), deployment solutions (Capistrano, Kubernetes, Docker Swarm), monitoring solutions (Nagios, Datadog), or local command execution (shell scripts, Rake tasks, Make). Instead Runbook is best used as a glue when needing to accomplish a task that cuts across these domains.

Quick Start

Installation

Add this line to your application's Gemfile:

ruby
gem 'runbook'

And then execute:

$ bundle

Or install it yourself as:

$ gem install runbook

Your First Runbook

Generate a runbook using the Runbook Generator:

$ runbook generate runbook my_first_runbook

Execute the runbook:

$ runbook exec my_first_runbook.rb

Slightly Longer Start

When setting up Runbook, you can install it at a system level, create a dedicated runbook project, or incorporate Runbook into an existing project.

System Level Setup

Install runbook at a system level using gem:

$ gem install runbook

Set any Runbook configuration in /etc/runbook.conf.

Generate runbook files using runbook generate runbook. Execute runbook generate help runbook for more details.

Installing Runbook at a system level can be useful for executing runbooks on remote hosts or within docker containers. One disadvantage of installing Runbook at a system level is that there is no built-in solution for dependency management.

New Project Setup

Install runbook using gem:

$ gem install runbook

Generate a new runbook project:

$ runbook generate project 

This will generate a new runbook project. Cd into your project directory and initialize its dependencies:

$ cd  && bin/setup

Existing Project Setup

Add this line to your project's Gemfile:

ruby
gem 'runbook'

Install the Runbook gem:

$ bundle install

Initialize Runbook in your project:

$ bundle exec runbook init

Contents

  • 1. Runbook Anatomy
    • 1.1 Entities, Statements, and Setters
      • 1.1.1 Books, Sections, Steps, and Setup
        • 1.1.1.1 Books
        • 1.1.1.2 Sections
        • 1.1.1.3 Steps
        • 1.1.1.4 Setup
        • 1.1.1.5 Tags and Labels
      • 1.1.2 Statements
        • 1.1.2.1 Ask
        • 1.1.2.2 Assert
        • 1.1.2.3 Capture
        • 1.1.2.4 Capture All
        • 1.1.2.5 Command
        • 1.1.2.6 Confirm
        • 1.1.2.7 Description
        • 1.1.2.8 Download
        • 1.1.2.9 Layout
        • 1.1.2.10 Note
        • 1.1.2.11 Notice
        • 1.1.2.12 Ruby Command
        • 1.1.2.13 Tmux Command
        • 1.1.2.14 Upload
        • 1.1.2.15 Wait
        • 1.1.2.16 Tmux Layouts
      • 1.1.3 Setters
  • 2. Working With Runbooks
    • 2.1 Via The Command Line
    • 2.2 From Within Your Project
    • 2.3 Self-executable
  • 3. Configuration
    • 3.1 Configuration Files
  • 4. Best Practices
    • 4.1 Iterative Automation
    • 4.2 Parameterizing Runbooks
    • 4.3 Passing State
    • 4.4 Execution Best Practices
    • 4.5 Remote Command Execution
    • 4.6 Composing Runbooks
    • 4.7 Deep Nesting
    • 4.8 Load Vs. Eval
  • 5. Generators
    • 5.1 Predefined Generators
    • 5.2 Custom Generators
  • 6. Extending Runbook
    • 6.1 Adding New Statements
    • 6.2 Adding Run and View Functionality
    • 6.3 DSL Extensions
    • 6.4 Adding Runs and Views
    • 6.5 Augmenting Functionality With Hooks
    • 6.6 Adding New Run Behaviors
    • 6.7 Adding to Runbook's Run Metadata
    • 6.8 Adding to Runbook's Configuration
  • 7. Testing
  • 8. Known Issues
  • 9. FAQ
  • 10. Development
  • 11. Contributing
  • 12. Feature Requests
  • 13. License
  • 14. Code of Conduct

Runbook Anatomy

Below is an example of a runbook:

ruby
Runbook.book "Restart Nginx" do
  description  25
    `echo 'Help! failure rate at #{failure_rate}' | mail -s 'High failure rate!' [email protected]`
  else
    `echo "Experienced failure rate of #{failure_rate}" | mail -s 'Help me eventually' not-urgent@my_site.com`
  end
  notice "Email sent!"
end

Metadata at execution time is structured as follows:

…

Additional methods that the ruby_command block has access to are:

  • metadata[:toolbox].prompt: A TTY::Prompt for retrieving input from the user
  • metadata[:toolbox].ask(msg): retrieve user input
  • metadata[:toolbox].yes?(msg): provide the user with a yes/no prompt
  • metadata[:toolbox].output(msg): output text to the user
  • metadata[:toolbox].warn(msg): output warning text to the user
  • metadata[:toolbox].error(msg): output error text to the user
  • metadata[:toolbox].exit(return_value): exit the process with the specified response code
Tmux Command

Runs the provided cmd in the specified pane.

ruby
tmux_command "tail -Fn 100 /var/log/nginx.log", :monitor_1
Upload

Uploads the specified file to to. An optional ssh_config can be specified to configure how the upload command gets run, for example specifying the remote host and remote directory to upload to. Optional options can be specified that get passed down to the underlying sshkit implementation

ruby
upload my_secrets.yml, to: secrets.yml, ssh_config: {servers: ["host1.prod"]}, options: {log_percent: 10}
Wait

Sleeps for the specified amount of time (in seconds)

ruby
wait 5
Tmux Layouts

Runbook provides native support for defining tmux layouts and executing commands in separate tmux panes. Layouts are specified by passing an array or hash to the layout statement in book blocks.

ruby
Runbook.book "My Book" do
  layout [
    :left,
    {name: :middle, directory: "/var/log", command: "tail -Fn 100 auth.log"},
    [:top_right, {name: :bottom_right, runbook_pane: true}]
  ]
end

When layout is passed as an array, each element of the array represents a pane stacked side-by-side with the other elements. Elements of the array can be symbols, hashes, or arrays.

Symbols and hashes represent panes. Hash keys for a pane include name, directory, command, and runbook_pane. name is the identifier used for the pane. This is used when specifying what pane you want to execute tmux commands in. directory indicates the starting directory of the pane. command is the initial command to execute in the pane when it is created. runbook_pane indicates which pane in the layout should hold the executing runbook. Only one pane should be designated as the runbook_pane and the runbook pane should not have a directory or command specified.

Arrays nested underneath the initial array split the pane from top to bottom. Arrays nested under these arrays split the pane from side to side, ad infinitum. You can start spliting panes from top to bottom as opposed to side-by-side by immediately nesting an array.

ruby
Runbook.book "Stacked Layout" do
  layout [[
    :top,
    :middle,
    :bottom,
  ]]
end

When a hash is passed to layout, the keys of the hash represent window names and the values represent pane layouts.

ruby
Runbook.book "Multi Window Layout" do
  layout({
    :web_monitor => [
      :left, :middle, :right,
    ],
    :db_monitor => [[
      :top, :middle, :bottom,
    ]]
  })
end

Notice in the example that parenthesis are used to wrap the hash. Ruby will raise a syntax error if layout's argument is not wrapped in parenthesis when passing a hash. Runbook expects that it is running in the last window in a tmux session. If you are running a runbook that uses a multi-window layout, the layout will not work unless runbook is running in the last window in the session.

If you want panes to be un-evenly spaced, you can replace the array of panes with a hash where the keys are panes and the values are numbers. The panes will be spaced according to the specified numbers.

ruby
Runbook.book "Uneven Layout" do
  layout [[
    {:left => 20, {name: :middle, runbook_pane: true} => 60

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyautomationautomation-frameworkdevopsdevops-tools

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理