I have two directories under /var/www/html, named vlp1 and vlp2 with Vagrant setup. If I run vagrant up separately in these folders the default local URL is vagrant.local for both. But vagrant.local/ always loads site from vlp1 folder.
As it should be, vagrant global-status shows that I have two virtual machines running under these directories. I require to run both sites side by side and to do this the only option I see is to have separate URLs. I believe there is a way to assign different URLs to different sites but don't have any idea how!
What I need to do to accomplish the above so that my sites run like local.vlp1.com and local.vlp2.com or may be like vagrant.vlp1 and vagrant.vlp2?
According to project instructions I have to keep two sites completely separated in two folders and have to use separate Vagrantfiles.
OS: Ubuntu 14.04 64 bit
Installed VitualBox version: 5.1
Installed Vagrant version: 1:1.9.4
Thank you!
UPDATE
Went through the following steps as advised by Henri:
Step 1:
$ vagrant global-status
Output:
id name provider state directory
------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox running /var/www/html/vlp2
Step 2: Did a graceful shutdown on vlp2
$ vagrant halt 190608c
Step 3: Output of vagrant global-status now is
id name provider state directory
-------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox poweroff /var/www/html/vlp2
Step 4:
$ sudo gedit /var/www/html/vlp2/Vagrantfile
if CONF['ip'] == "dhcp"
config.vm.network :private_network, type: "dhcp", hostsupdater: "skip"
else
config.vm.network :private_network, ip: "192.168.2.5"
end
Step 5: Re up'd vlp2 machine
$ vagrant up 190608c
Step 6:
$ vagrant global-status now shows both machine are back to running state again.
id name provider state directory
------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox running /var/www/html/vlp2
Step 7:
In /etc/hosts added following entry
192.168.2.5 vagrant.vlp2
Finally I tried vagrant.vlp2/ in browser but ended up with the following message:
This site can’t be reached
http://vagrant.vlp2/ is unreachable.
As I understand you're using multiple VM so the easiest in this case is to assign each of the VM a static IP (that must be different) so you do so in Vagrantfile
Vagrant.configure("2") do |config|
...
config.vm.network "private_network", ip: "192.168.10.x"
...
end
and you use another IP for the second VM
Vagrant.configure("2") do |config|
...
config.vm.network "private_network", ip: "192.168.20.y"
...
end
and then you update your /etc/hosts file with the information
192.168.10.x vagrant.vlp1
192.168.20.y vagrant.vlp2
Related
First, apologies: I'm a newbie.
I've created a very basic Vagrantfile by running Vagrant init. I only made a few changes:
config.vm.box = "generic/fedora28"
config.vm.box_version = "1.8.32"
config.vm.provider "libvirt" do |lv|
lv.memory = "4096"
end
(There are also a few items in my config.vm.provision section).
After running vagrant up , the process gets stuck at
==> default: Waiting for domain to get an IP address...
I'm running this off a Fedora 27 box, which uses version 2.0.2 of the Vagrant package (even though current is 2.1.5).
I've tried adding this line:
config.vm.network "private_network", ip: "192.168.100.101"
but it had no effect.
Can anyone help?
I have a Vagrant File that spins up 4 VMs, of image generic/ubuntu2004 on libvirt kvm, to make a k3s cluster that's accessible on the LAN. (multipass + k3s is only accessible via localhost b/c it doesn't allow easy bridging.)
I ran both of these commands > 50 times
sudo vagrant destroy --force --parallel
sudo vagrant up
On the ~51'st time, I noticed vagrant up got stuck on "Waiting for domain to get an IP address..."
What fixed it for me was sudo reboot. You know the classic have you tried unplugging it and plugging it back in?
Something else to try (I rebooted before trying it)
https://bugzilla.redhat.com/show_bug.cgi?id=1283989
I've set up 4 VMs in Vagrant and now trying to set the name of a VM in Vagrant as I don't just want to ssh into the default VM.
I can't find any docs on the vagrant website but found this:
How to change Vagrant 'default' machine name?
However, when I try:
config.vm.define "foohost"
and do a vagrant up I get:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* The following settings shouldn't exist: define
I suspect you actually wrote
config.vm.define = "foohost"
rather than
config.vm.define "foohost"
as that would explain the error message. (Best to show several lines of actual source if you can.)
as I don't just want to ssh into the default VM.
so when you use multiple VM, you can tell vagrant which VM you want to ssh by default, using the following
config.vm.define "foohost", primary: true do |foohost|
...
end
then when you run vagrant ssh you will ssh by default in this VM.
To ssh into the other MV, you will need to specify the VM name
I have a custom vagrant box based on the offcial box ubuntu 16.04.
I simplly run like this to get the packaged box.
vagrant init ubuntu/xenial64; vagrant up --provider virtualbox
vagrant up
vagrant ssh # enter the virtual machine and do some custom change on it
vagrant halt
vagrant package --vagrantfile Vagrantfile --output custom_ubuntu1604.box
and then i copy the file custom_ubuntu1604.box to another directory, i use the box like this:
vagrant box add ubuntu1604base custom_ubuntu1604.box
vagrant init ubuntu1604base
vagrant up # at this point the machine will be stopped at "Started Journal Servie"
my new virtualbox machine base on the new packaged box will stop at:
the screenshot
And finally it timed out:
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within the
configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that Vagrant
had when attempting to connect to the machine. These errors are
usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes. Verify
that authentication configurations are also setup properly, as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
Try to set config.vm.boot_timeout in Vagrantfile more than default e.x.600. From my experience I found out it take a long time at the first time to connecting guest machine.
For example
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provider "virtualbox"
config.vm.boot_timeout = 600
end
I have just started working with Vagrant. After starting guest machine and making some changes (e.g. installed some updates and python virtualenvs). And after few (vagrant halt and vagrant reload) when I ssh-ed into guest machine I noticed that all my changes disappeared. When I opened the Virtualbox I saw that there were two boxes with the name of my folder with guest os and on every vagrant up it seems like it is starting the second machine. When I started the first guest os through virtual box interface I saw that my data was present. How can I start with vagrant the first machine? Should I delete the second? When was it created?
Start with vagrant up
Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "trusty_14"
config.vm.network "forwarded_port", guest: 8000, host: 8000
end`
So I tried to vagrant destroy. The second machine was deleted indeed, but after vagrant up the new one was created.
Then I checked the id's following #Frédéric Henri advice, and in id file was id of second machine, so I have replaced it with the id of first machine from VBoxManage list vms, and everything works!
But still did not get how and when the second machine was created...
The boxes were working fine. Then I halted one (the only one running at the time) and now I can't get either of them back up.
Running vagrant up [name] gives me the following error, regardless of which I pick or whether I leave it at vagrant up for them both to come up:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* A box must be specified.
Running latest version of Vagrant (1.7.4).
Here is my Vagrantfile in its entirety, comments included (just in case):
# Search for boxes here: https://atlas.hashicorp.com/boxes/search
# Refer to commands_vagrant.txt for command reference
Vagrant.configure("2") do |config|
# Globally defined variables
config.vm.synced_folder "./", "/var/www/public"
# CentOS 6.5, Apache 2.2.15, MySQL 5.5.36 (-u root), PHP 5.3.28
# Note: If PHP session keys don't work, set permissions to 777 (or other more restrictive, but this is guaranteed to work) on /var/lib/php/session
config.vm.define "php5dot3", primary: true do |php5dot3|
config.vm.box = "smallhadroncollider/centos-6.5-lamp"
config.vm.network :forwarded_port, guest: 80, host: 4567
end
# Ubuntu 14.04 (SSH pw: vagrant), Apache 2.4.12, MySQL 5.5.43 (-u root -p root), PHP 5.6.10
config.vm.define "php5dot6" do |php5dot6|
config.vm.box = "scotch/box"
config.vm.network :forwarded_port, guest: 80, host: 4568
end
end
Result of running vagrant status:
Current machine states:
php5dot3 poweroff (virtualbox)
php5dot6 poweroff (virtualbox)
Result of running vagrant global-status:
id name provider state directory
--------------------------------------------------------------------------
e1f3c85 default virtualbox poweroff /home/sam/Web
c588d51 php5dot6 virtualbox poweroff /home/sam/Web
4e71c50 php5dot3 virtualbox poweroff /home/sam/Web
'default' was the singular box I had in my Vagrantfile before I got multi-machines working last week. (Relevant?)
Result of running vagrant box list:
scotch/box (virtualbox, 2.0)
smallhadroncollider/centos-6.5-lamp (virtualbox, 1.0.0)
Any help would be appreciated, thanks.
Inside of your machine definitions, you need to use the variable name of that machine, instead of config. Try this out:
In the file below, I've changed config.vm to either php5dot3.vm or php5dot6.vm:
Vagrant.configure("2") do |config|
# Globally defined variables
config.vm.synced_folder "./", "/var/www/public"
# CentOS 6.5, Apache 2.2.15, MySQL 5.5.36 (-u root), PHP 5.3.28
# Note: If PHP session keys don't work, set permissions to 777 (or other more restrictive, but this is guaranteed to work) on /var/lib/php/session
config.vm.define "php5dot3", primary: true do |php5dot3|
php5dot3.vm.box = "smallhadroncollider/centos-6.5-lamp"
php5dot3.vm.network :forwarded_port, guest: 80, host: 4567
end
# Ubuntu 14.04 (SSH pw: vagrant), Apache 2.4.12, MySQL 5.5.43 (-u root -p root), PHP 5.6.10
config.vm.define "php5dot6", autostart:false do |php5dot6|
php5dot6.vm.box = "scotch/box"
php5dot6.vm.network :forwarded_port, guest: 80, host: 4568
end
end
I also added autostart:false to the definition of your php5dot6 box, which you can remove if you wish. (It just means that running vagrant up will only start the primary by default.
If you are getting this error with DigitalOcean, you may need their plugin:
vagrant plugin install vagrant-digitalocean
Installing the 'vagrant-digitalocean' plugin. This can take a few minutes...
Fetching: multipart-post-2.0.0.gem (100%)
Fetching: faraday-0.15.4.gem (100%)
Fetching: vagrant-digitalocean-0.9.3.gem (100%)
For someone that is having this issue now:
I had deleted my Vagrantfile before trying to destroy it. You need to run the vagrant destroy command from the right directory where the Vagrantfile for that process is.
Run vagrant ssh-config and look at the directory column.
If you, like me, deleted the file, do:
vagrant init
Then
vagrant destroy $id
P.S.: Use sudo if you have permission issues running those commands.