Created
February 26, 2016 09:50
-
-
Save kesonno/11c458caea4698345d56 to your computer and use it in GitHub Desktop.
Ask for user input in Vagrantfile during provisioning phase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
for anyone else coming up on this - VM_NAME needs to be your VM name. Try replacing it with default
or look at the location .vagrant/machines for the directory and you will see.
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
Hello Can you help me out a bit with the if Dir.glob("#{File.dirname(FILE)}/.vagrant/machines/#{VM_NAME}/*").empty? || ARGV[1] == '--provision' please , the problem I'm having is that the prompt gets executed on every vagrant command , i only need to run it on vagrant up