Skip to content

Instantly share code, notes, and snippets.

@kesonno
Created February 26, 2016 09:50
Show Gist options
  • Save kesonno/11c458caea4698345d56 to your computer and use it in GitHub Desktop.
Save kesonno/11c458caea4698345d56 to your computer and use it in GitHub Desktop.
Ask for user input in Vagrantfile during provisioning phase
if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/#{VM_NAME}/*").empty? || ARGV[1] == '--provision'
print "Please insert your credentials\n"
print "Username: "
username = STDIN.gets.chomp
print "Password: "
password = STDIN.noecho(&:gets).chomp
print "\n"
config.vm.provision :shell, :path => "provision-vagrant.sh", :args => [username, password]
end
@nickvoegeli
Copy link

nickvoegeli commented Aug 11, 2017

Super helpful, thanks! I used this basic idea to create shared folders for two related repos in the same VM:

  print "Enter the path to the sites repo: "
  sites_repo_path = STDIN.gets.chomp
  print "\n"

  # Share an additional folder to the guest VM. The first argument is the path on the host to the actual folder.
  # The second argument is the path on the guest to mount the folder.
  config.vm.synced_folder "./", "/var/www/html", group: "www-data", user: "vagrant"
  config.vm.synced_folder sites_repo_path + '/app/Config/Sites', "/var/www/html/app/Config/Sites", group: "www-data", user: "vagrant"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment