Comments (1)
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:
- 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.
- 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)
- cd exit status: 127 (SSHKit::Command::Failed) HOT 4
- How does "previous position detected" work? HOT 2
- Dealing with errors HOT 2
- Long running processes HOT 5
- tmux_command HOT 2
- tmux_command doesn't seem to respect server HOT 2
- command `curl` doesn't do what I expected HOT 1
- Ability to set `report_on_exception = false`? HOT 2
- rescue from command Exception HOT 2
- Ruby 3 compatibility issue? :into keyword in `ask?` HOT 2
- Builds broken after version bump to 1.0
- Switch to Github Actions?
- Is Local Command Execution supported? HOT 1
- Add support for Ruby 3.1
- Crash when generating projects with `-`
- Jump to specific Position doesn't check input
- DidYouMean update
- Clarification: context of `path`
- Incompatibilities to tmux version 3.4 HOT 2
- Maintained repo or alternative HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from runbook.