Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Answering prompt using vagrant file?

Is it possible to add a script to a Vagrantfile that answers a prompt. I am provisioning a ubuntu box for docker

config.vm.box = "ubuntu"

config.vm.provision :shell, :inline => "sudo apt-get update"

config.vm.provision :shell, :inline => "sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring"

After running the last command, there is a prompt that asks

Do you want to continue [Y/n]?
like image 253
user3689824 Avatar asked May 31 '14 19:05

user3689824


People also ask

Where is my vagrant file?

By default, Vagrant shares your project directory (the one containing the Vagrantfile) to the /vagrant directory in your guest machine.

How does vagrant find the first Vagrantfile?

When you run any vagrant command, Vagrant climbs up the directory tree looking for the first Vagrantfile it can find, starting first in the current directory. So if you run vagrant in /home/mitchellh/projects/foo, it will search the following paths in order for a Vagrantfile, until it finds one:

Why do I need to commit a Vagrantfile to version control?

Vagrant is meant to run with one Vagrantfile per project, and the Vagrantfile is supposed to be committed to version control. This allows other developers involved in the project to check out the code, run vagrant up, and be on their way.

What is the purpose of a Vagrantfile?

Vagrant is meant to run with one Vagrantfile per project, and the Vagrantfile is supposed to be committed to version control. This allows other developers involved in the project to check out the code, run vagrant up, and be on their way. Vagrantfiles are portable across every platform Vagrant supports.

How to run vagrant from any directory?

So if you run vagrant in /home/mitchellh/projects/foo , it will search the following paths in order for a Vagrantfile, until it finds one: This feature lets you run vagrant from any directory in your project.


1 Answers

An easier solution would be to use the -y option of apt-get:

config.vm.provision :shell, :inline => "sudo apt-get -y install linux-image-generic-lts-raring linux-headers-generic-lts-raring"

See the manual:

-y, --yes, --assume-yes Automatic yes to prompts. Assume "yes" as answer to all prompts and run non-interactively. If an undesirable situation, such as changing a held package or removing an essential package, occurs then apt-get will abort.

like image 141
Gergo Erdosi Avatar answered Sep 25 '22 01:09

Gergo Erdosi