vagrant private network fails to resolve on windows 10 host - vagrant

I can't get anything to work. I have windows 10 as my host and my guest VM is centos/7 box. It works great with forwarded_ports but using private_network setting nothing resolves. I'm not sure what to do or check
vagrant file look like
Vagrant.configure("2") do |config|
config.vm.box = "bento/centos-7.4"
config.vm.synced_folder "./website", "/var/www/html/", :mount_options => ["dmode=777", "fmode=777"], owner: "apache", group: "apache"
config.vm.network "private_network", ip: "192.168.50.4"
## Bootstrap script to provision box. All installation methods can go here.
config.vm.provision "shell" do |s|
s.path = "bootstrap.sh"
end
end
My ifconfig on guest looks like
My virtualbox shows two adapters
I get nothing when I browse to the IP on windows

It actually had nothing to do with vagrant. It was all set up correctly, but my magento site had a weird error. Thanks to Frederic for taking the time!

Related

Vagrantbox with Hyper-V not starting

I'm trying to setup a vagrantbox with Hyper-V on my local windows-10 mashine. My Workstation is running behind a proxy, but I configured a local cntlm proxy to get around these limitations. Proxy settings work fine since I was able to install a vagrant plugin and downloan a box image.
But now my guest linux does not start up and I am running out of ideas.
My vagrant file
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-18.04" # ubuntu 18.04 image with support for virtual box and Hyper-V
config.vm.hostname = "skywalker"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.provider "hyperv" do |hv|
hv.memory = "2048"
end
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" # prevent tty errors
# install the vagrant plugin "vagrant-cachier" to cache downloaded artifacts
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
# vagrant behing local cntlm proxy if plugin exists (= provinzial win10 workstation)
if !Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "http://localhost:3128/"
config.proxy.https = "http://localhost:3128/"
config.proxy.no_proxy = "localhost, 127.0.0.1"
end
# --------------------------------------------------------------------------
# provision virtual mashine (basic setup) and install applications in VM
#config.vm.provision "shell", path: "scripts/install-ansible.sh"
config.vm.provision "shell", path: "scripts/install-ncdu.sh"
config.vm.provision "shell", path: "scripts/install-git.sh"
config.vm.provision "shell", path: "scripts/install-openjdk-11.sh"
config.vm.provision "shell", path: "scripts/install-maven.sh"
config.vm.provision "shell", path: "scripts/install-node-npm.sh"
config.vm.provision "shell", path: "scripts/install-docker.sh"
config.vm.provision "shell", path: "scripts/install-docker-compose.sh"
# npm webserver
config.vm.provision "shell", path: "apps/install-npm-apps.sh"
config.vm.network "forwarded_port", guest: 8000, host: 8000
# artifactory setup (start artifactory after vm startup)
config.vm.network "forwarded_port", guest: 8081, host: 8081 # artifactory from docker
config.vm.network "forwarded_port", guest: 8082, host: 8082 # artifactory from docker
# See README.md for Artifactory in Docker
end
Starting the box with this settings results in
C:\home\work\workspace\vagrant-boxes\skywalker (master -> origin)
λ vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
==> default: Importing a Hyper-V instance
default: Creating and registering the VM...
default: Successfully imported VM
default: Configuring the VM...
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
default: Timeout: 120 seconds
default: IP: fe80::215:5dff:fe02:8b01
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: fe80::215:5dff:fe02:8b01:22
default: SSH username: vagrant
default: SSH auth method: private key
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.
On a different mashine with VirtualBox as VM provider this Vagrantfile works fine. Sadly I cannot use any VM provider other than Hyper-V on my windows mashine due to limitations which are out of my control ...
I set up Hyper-V using Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All.
Any ideas? Thanks in advance and best regards. Sebastian
I went through this exercise last week and saw similar problems. I made lot of progress following these steps and the vm's get spun up at a reasonable time under windows 10 hyper-v. This is what i did.
Followed this blog and tried creating a vm successfully first.
https://win32.io/posts/Vagrant-Install-HyperV
Then i created a simple vagrantfile and got it to work successfully. Here is mine ,
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.hostname = 'utility-server-1'
config.vm.network 'public_network', bridge: 'Internet'
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider "hyperv" do |vb|
vb.memory = "4024"
vb.cpus = 2
vb.vmname = 'utility-server-1'
end
end
Once this works, add more complex steps from your vagrantfile, like shell scripts and forwarded ports.

Vagrant Vagrantfile config

I have this vagranfile for box "centos/7"
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/home/vagrant"
config.vm.provision "shell", path: "./conf/bitrix-env.sh"
config.vm.boot_timeout = 100
config.vm.provider :virtualbox do |vb|
vb.gui = true
vb.memory = "1024"
end
end
vagrant up - command works clear, but scripts in provision don't install
after i tried to start vagrant provision, but had an error:
SSH is getting permission denied errors when attempting to connect
to the IP for SSH. This is usually caused by network rules and not being
able to connect to the specified IP. Please try changing the IP on
which the guest machine binds to for SSH.
How can i fix this and install all provisions?
The problem is due to the below line in your vagrantfile
config.vm.synced_folder '.', '/home/vagrant'
The authorized_keys file for the vagrant user is located in /home/vagrant/.ssh inside the vagrant machine, which enables to ssh into the vagrant box.
As you are mounting your current directory to /home/vagrant, all the contents of /home/vagrant are over-written and there is no authorized key file.
Change the mount path to anything except /home/vagrant, and you will able to ssh into the machine. As example
config.vm.synced_folder '.', '/home/vagrant/somepath'

Connecting my vagrant and another VM in VirtualBox

For my web development, I use a vagrant install to run a local instance of the website with the following config:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network :forwarded_port, host: 4567, guest: 80
config.vm.hostname = "some-website"
config.vm.synced_folder ".", "/var/www/public", :mount_options => ["dmode=777", "fmode=666"]
config.vm.provision :shell, path: "bootstrap.sh", :args => "some-website", privileged: false
end
This website is accessible in the browser on the specified IP.
However, I also have VM's for cross browser testing and these VM's don't have access to the IP address of the Vagrant box.
I need them to connect, because I want to do cross browser testing on that locally running vagrant box.
A couple of StackOverflow searches gave me the option of changing the private_network to a public_network, but then I can't access the IP anymore.
Also adding virtualbox__intnet: true doesn't work.
Would anyone be able to come up with a solution for this? It would be great if I could access the IP from the IE9 VM, directly into the Vagrant VM.
So, to clarify, currently:
Laptop can access Vagrant (laptop -> VM)
IE9 VM can't access Vagrant (VM -!> VM)
What I want:
Laptop can access Vagrant (laptop -> VM)
IE9 VM can access Vagrant (VM -> VM)
As Frédéric pointed out: the private_network is actually accessible from another VM on the same host.
My problem seemed to be WordPress itself and not related to Vagrant or the VM setup.

Vagrant provisioning script is not being copied to host location

Host: Windows 7
Guest: Windows 8
I have a simple Vagrantfile that runs a powershell script to provision the guest. When I packaged the box, I saw that the file was added, but when I run vagrant up I get the error shell provisioner:* `path` for shell provisioner does not exist on the host system: D:/VirtualMachines/test/provision.ps1
I verified that provision.ps1 exists in the vagrant box location under the include directory.
So why isn't provision.ps1 getting copied to the location it needs to when i run vagrant up?
Vagrant file:
VAGRANTFILE_API_VERSION = "2"
modified_name = ENV["COMPUTERNAME"][0..12]
comp_name = modified_name + "TA"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "base"
config.vm.hostname = comp_name
config.vm.communicator = "winrm"
config.vm.network "forwarded_port", host: 3389, guest: 3389, auto_correct: true
config.vm.provision "shell", path: "provision.ps1"
end
The answer at How to package files with a Vagrant box? helped me.
Here is how I got it to work:
config.vm.provision "shell" do |s|
p = File.expand_path("../", __FILE__)
s.path = p + "\\provision.ps1"
end
I had the same problem with Vagrant 1.8.1 on host Windows 8. After reading https://github.com/fideloper/Vaprobash/issues/30 I just renamed bootstrap.sh to bootstrp.sh, tried again and it worked. After renaming bootstrp.sh to bootstrap.sh it still worked.
I suppose in my case there was some strange invisible character in the filename.

How to access Vagrant Box in public network

I had created on e box inside vagrant. In the Vagrantfile, I had given the network as
Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network :private_network, ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network :public_network
I can't access the VagrantBox outside the VLAN. I need to access the Vagrant Box in public network. How to configure vagrantfile in such a way that I need to access in public network?
Uncomment the line in Vagrantfile
config.vm.network :public_network
The file will look like below
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "box_name"
config.vm.network :public_network
end
Save it, restart the VM by using vagrant reload.
For VirtualBox, it'll use Bridged mode for networking. Which means the VM will acquire an IP address from the DHCP server for the VLAN.
You can also set the VLAN IP with: config.vm.network :public_network, ip: "192.168.0.160"
Refer to => Public Network
By default, vagrant deletes the default (working) route on additional bridged networks inside the VMs. My problem which was specific for DHCP could only be solved by configuring the bridged network as follows:
config.vm.network :public_network, :bridge => 'em1',:use_dhcp_assigned_default_route => true
Courtesy of https://groups.google.com/forum/#!msg/vagrant-up/yNhWV42pcgk/NbOck1xqtFQJ
There maybe an equivalent for static IPs.
I was unable to figure this out using anything I read (which was hours and hours of research). Instead, this is how I figured it out:
Below is my Vagrantfile. The important part for me was config.vm.network :public_network. After reloading vagrant with vagrant reload, I chose the first option of the 4 available bridged network interfaces (I’m not sure if I chose the correct one by luck, or if any would have worked, I’ll experiment), then sshed into the vagrant box with vagrant ssh, did ifconfig, chose one of the 3 ip addresses that it output, pasted that into my browser, and it worked.
The thing no one else seemed to talk about was sshing into the vagrant box and finding one of the ip addresses there. I hope maybe this helps some other networking newb in the future.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "bahmni-team/bahmni"
config.vm.box_check_update = true
config.ssh.insert_key = false
config.vm.network :public_network
config.vm.synced_folder "..", "/bahmni", :owner => "vagrant"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", 4092, "--cpus", 2, "--name", "Bahmni-RPM"]
end
end
Finally! This is years later but I couldn't find more current info. For me, the problem was that I not only had a private network defined, but also a forwarded port, and all that was working well. I then commented out the private_network, replaced it with public_network, and couldn't reach anything. Tried everything I found here and elsewhere, no go. It's only when I commented out the port forwarding that things started working again, without any of the manual bridging/dhcp configuration rigamarole suggested.
Single VM environment
you can use command: vagrant ssh
Multi VM environment
you can use command: vagrant ssh {hostname}

Resources