I am playing around with user input using ruby inside a trigger during vagrant up. However, the variable I save the input to is empty when it is being used in a later provisioning step.
The below code works, I can reference $NetworkPassword later in a provisioning step. The downside is that the code is always run, also for other Vagrant commands like destroy.
Vagrant.configure("2") do |config| $NetworkPassword = "" if $NetworkPassword.empty? puts "Enter NetworkPassword" $NetworkPassword = STDIN.noecho(&:gets).chomp end
The below command will only run as part of vagrant up because it is placed inside a trigger. The problem here is that $NetworkPassword is empty when it is later referenced in a provisioning step.
Vagrant.configure("2") do |config| $NetworkPassword = "" config.trigger.before :up do |trigger| # --- Ask user input for empty parameters trigger.ruby do |env, machine| if $NetworkPassword.empty? puts "Enter NetworkPassword" $NetworkPassword = STDIN.gets.chomp end end end
What am I doing wrong here? How can I run ruby code to assign a value to a variable such that the value is available when the variable is later referenced in a provisioning step?