Giter Club home page Giter Club logo

Comments (1)

pblesi avatar pblesi commented on July 28, 2024

I like this idea, but have struggled to find a good implementation. If you can think of a good way to accomplish this, I would be interested. A couple of thoughts:

  1. Typically for gathering input at compile time, I suggest relying on environment variables.
Runbook.book "Bootstrap Servers" do
  step "Setup" do
    ruby_command do
      @rails_env ||= ENV["RAILS_ENV"]
      ask "Environment?", into: :rails_env, default: "staging" unless @rails_env
    end
  end
end
$ RAILS_ENV=production bundle exec runbook exec my_runbook.rb 

Alternatively, TTY::Prompt is a dependency of Runbook, so it could be used to collect user input before the runbook is evaluated. The main concern with this is it prevents a transition to full autonomy for the runbook. If this is unlikely to be necessary for your particular use case, then this approach may be a good route to go. Another downside of this is that you will be re-prompted every time you execute the runbook, even if you encounter an error. It also will not remember previous inputs.

  1. Switching to some OOP might be useful. You could do something like the following:
# runbooks/restart_cluster.rb
require 'rotate_leader_runbook'
require 'restart_node_runbook'

Runbook.book "Restart Cluster" do
  section "setup" do
    add RotateLeaderRunbook.input_step
    add RestartLeaderRunbook.input_step
  end

  add RotateLeaderRunbook.rotate_leader_section
  add RotateLeaderRunbook.restart_node_section
end
# lib/runbook/rotate_leader_runbook.rb

module RotateLeaderRunbook
  def self.input_step
    Runbook.step do
      ask "Server?", into: server
      ask "Timeout?", into: timeout
    end
  end

  def self.rotate_leader_section
    Runbook.section "Rotate Leader" do
      # ...
    end
  end
end

This way, you could coalesce inputs to all execute at the beginning of the runbook.

I'm also going to mention that I am planning to include this feature in the next version of Runbook: https://github.com/braintree/runbook/blob/master/TODO.md#always-executed-setup-section. This may not directly address your issue, but may be useful for your mega runbook o' doom.

from runbook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.