Closed Jazb closed 4 years ago
Hi Jesus,
You are correct that ask
receives its value at runtime, but server
is evaluated at compile time, so it will have already executed by the time ask
is executed.
You have a couple options.
1) You can define the commands in a ruby_command
block because this is evaluated at runtime.
ask "Name of server to restart", into: :target_host, default: "localhost"
ruby_command do |rb_cmd, metadata, run|
command "whoami", ssh_config: {servers: [target_host], user: "jazb"}
end
2) You can pass the host in as an environment variable, or have it somehow be set outside of the runbook.
target_host = ENV["TARGET_HOST"] || "localhost"
Runbook.book "Restart Nginx" do
section "Restart Nginx" do
server target_host
user "jazb"
step "Define server to restart" do
wait 5
end
step "Stop Nginx" do
note "Stopping Nginx..."
command "whoami"
end
end
end
I'm going to close this issue, but feel free to reopen it if you run into further issues.
How can I do so that a previous step can ask me about the server to use
I have tried a series of things with "ask" but it doesn't work, I understand that the server stament is part of the runbook DSL and receives only one string but in what way can I make it modular and save in a variable and then define it, my best try has been the next: