Reputation: 18860
can I vagrant up
just one machine from multi-machine setup?
or
how could I have different setups for developing e.g. local
, test
and production
? do I have to have different Vagrantfile
s?
example Vagrantfile
(taken from Multi-Machine Doc page)
Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: "echo Hello"
config.vm.define "web" do |web|
web.vm.box = "apache"
end
config.vm.define "db" do |db|
db.vm.box = "mysql"
end
end
Upvotes: 2
Views: 3106
Reputation: 2595
vagrant up machine_name
.
In your config it could be vagrant up web
.By setting autostart: false
in machine configuration, you block autostart of the machine in vagrant up
call. More about vagrant multi-machine configuration here.
2.There are many ways to have different setups in vagrant.
a. Define different machines with different provisions scripts :
config.vm.define "m1", autostart: false do |m1|
m1.vm.provision "shell" do |s|
s.path = "path_to/m1_provision_script.sh"
end
end
config.vm.define "m2", autostart: false do |m2|
m2.vm.provision "shell" do |s|
s.path = "path_to/m2_provision_script.sh"
end
end
b. Provide different parameter to provision script:
config.vm.define "m1", autostart: false do |m1|
m1.vm.provision "shell" do |s|
s.path = "path_to/provision_script.sh"
s.args = "machine_1"
end
end
config.vm.define "m2", autostart: false do |m2|
m2.vm.provision "shell" do |s|
s.path = "path_to/provision_script.sh"
s.args = "machine_2"
end
end
c. If you are using puppet as a provisioner, you can also define custom fact the will indicate if machine is local
, test
or prod
.
Upvotes: 1