Vagrant ssh hangs after successful boot of host - vagrant

Below is my Vagrantfile, while booting up this host, it gets stuck at
==> sawtoothclient: Waiting for machine to boot. This may take a few minutes...
sawtoothclient: SSH address: 127.0.0.1:2222
sawtoothclient: SSH username: vagrant
sawtoothclient: SSH auth method: private key
Vagrant reload didnt help, I dont want to vagrant halt everytime I login on to my virtualhost.
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "sawtoothclient", primary: true do |sawtoothclient|
sawtoothclient.vm.box = "ubuntu/xenial64"
sawtoothclient.vm.hostname ="sawtoothclient"
sawtoothclient.vm.network :public_network
#fubuntuone.vm.provision :shell, :privileged => false, :path => "bootstrap_ubuntu.sh"
sawtoothclient.vm.synced_folder "/home/feynman/Programs/SawtoothClient/", "/home/vagrant/SawtoothClient/"
sawtoothclient.vm.provider :virtualbox do |vb|
vb.gui = false
vb.memory = 2048
#vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
#vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end
end
My UFW firewall rules are
To Action From
-- ------ ----
Anywhere ALLOW 192.168.1.0/24
But when I added
sudo ufw allow 22
vagrant ssh succeeded, I couldnt understand why, From my understanding, vagrant must have been using the host machine IP to ssh into the vagrant host, which is already covered in the firewall rule added initially to the ufw firewall.
Vagrant 2.1.4
vboxmanage -v
output: 5.2.18r124319

Related

Can I force provisioning to happen before mounting shared folders in Vagrant?

I have the following Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/6"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network :forwarded_port, host: 8080, guest: 80
config.vm.network :forwarded_port, host: 3306, guest: 3306
config.vm.synced_folder "../../applications", "/var/www/html", :owner=>"apache", :group=>"apache"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.name = "appserver"
end
end
Each time I run vagrant up (for first time, let's say that first I ran vagrant destroy -f) I end up with the following error:
==> default: Mounting shared folders...
default: /vagrant => E:/Development/vagrant/centos6
default: /var/www/html => E:/Development/applications/arx
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
id -u apache
The error output from the command was:
id: apache: No such user
The error is pretty clear "apache user does not exists". As I am seeing this there is two or "three" ways to fix this:
By removing the :owner=>"apache", :group=>"apache" portion from the synced_folder. This is a BIG no, at least for me because if I remove them then the folder will be owned by vagrant which will/could cause issues while apache tries to read something from /var/www/html.
By commenting the line config.vm.synced_folder, getting up the box so everything gets installed and setup, then shutting down the box and getting up again with the line uncommented: it works but still an ugly solution
By forcing the provisioning to happen before anything gets mounted: the ideal solution.
Does any know if this is possible and if so how? I wasn't able to found anything regarding the 3rd solution :( if you have a better solution you're more than welcome to post here it might help me and others probably.
I have found this and this but is not helpful.
one potential solution would be to run apache as vagrant user.
In your /etc/httpd/conf you can replace the User and Group value as
User vagrant
Group vagrant
so you can continue sharing your folder with vagrant user and httpd will be run as vagrant user.
You can use numeric ids and then create an user
config.vm.synced_folder '${HOSTDIR}', '${EXPORTDIR}', type: "virtualbox", owner: '123', group: '456'
config.vm.provision :shell, inline: "useradd --system -g '456' -u '123' -d '${EXPORTDIR}' --shell /bin/false apache"

Vagrant Up (private_network) Error : default: Warning: Connection aborted. Retrying

I have the following Vagranfile. When I vagrant up, I'm getting the following error. However, if I switch to use a config.vm.network "public_network", everything works fine.
But I still want to use config.vm.network "private_network" so I can assign fixed IP address for development.
[Error]
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection aborted. Retrying...
default: Warning: Connection aborted. Retrying...
[Vagrantfile]
Vagrant.configure("2") do |config|
config.vm.box = "pef"
config.vm.network "private_network", ip: "192.168.33.12"
#config.vm.network "public_network"
config.vm.synced_folder "C:/Users/user1/myprj", "/home/vagrant"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "1024"
# For host-only adapter
vb.customize ["modifyvm", :id, "--uartmode1", "disconnected" ]
vb.customize ["modifyvm", :id, "--nictype1", "Am79C973"]
vb.customize ["modifyvm", :id, "--nictype2", "Am79C973"]
end
end
I had this issue which is confusing. First thing you need to know, is the problem causing timeout.
If you're using VirtualBox, you can add this to your VagrantFile :
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
vb.gui = true
That will launch VirtualBox window and help you understand the potential error you have during the booting process of your VM.
In my case, I tried several things and ended up raising Vagrant time out to 600 :
config.vm.boot_timeout = 600
You can also read to this feed on StackOverflow , it describes the same issue :
Vagrant up timeout

Vagrant up - The Following settings shouldn't exist: vm (rethinkdb-vagrant)

Trying to setup rethinkdb using https://github.com/RyanAmos/rethinkdb-vagrant
C:\rethinkdb-vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:
VirtualBox Provider:
* The following settings shouldn't exist: vm
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Ubuntu 12.04, 64 bit
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
# Providers
config.vm.provider :virtualbox do |p|
p.vm.customize ['modifyvm', :id, '--memory', '512', '--ioapic', 'on']
end
# SSH
config.ssh.username = "vagrant"
# Port Forwarding
config.vm.network :forwarded_port, guest: 8080, host: 8080
config.vm.network :forwarded_port, guest: 28015, host: 28015
config.vm.network :forwarded_port, guest: 29015, host: 29015
# Attempt to 'guess' the default network
config.vm.network :public_network, :bridge => 'en0: Wi-Fi (AirPort)'
# Provisioning
config.vm.provision :shell do |sh|
sh.inline = <<-EOF
export DEBIAN_FRONTEND=noninteractive;
apt-get update --assume-yes;
apt-get install --assume-yes python-software-properties;
add-apt-repository --yes ppa:rethinkdb/ppa 2>&1;
apt-get update --assume-yes;
apt-get install --assume-yes rethinkdb;
sed -e 's/somebody/root/g' -e 's/somegroup/root/g' -e 's/# bind=127.0.0.1/bind=all/g' /etc/rethinkdb/default.conf.sample > /etc/rethinkdb/instances.d/default.conf
rethinkdb create -d /var/lib/rethinkdb/instances.d/default 2>&1;
service rethinkdb start;
EOF
end
end
The issue is at this section:
# Providers
config.vm.provider :virtualbox do |p|
p.vm.customize ['modifyvm', :id, '--memory', '512', '--ioapic', 'on']
end
where p.vm.customize should just be p.customize since as the outer loop shows, vm is parent to provider and customize hangs directly off of provider.
So the correct block would be:
# Providers
config.vm.provider :virtualbox do |p|
p.customize ['modifyvm', :id, '--memory', '512', '--ioapic', 'on']
end
If you run:
vagrant global-status
you will see all the possible machines that might be running on your computer.
Then take those machines and go
vagrant suspend [machine id]
Further more you can open Virtual Box and Power Off those machines manually from that GUI, which should free up the ports.

access private VM from other computer over wifi

I have a private network VM for developing on my mac. I'd like for my android device to be able to communicate with the VM on my mac. Currently I can visit the IP defined in my Vagrantfile, 10.10.10.10, on my mac and access it just fine but I can't access it via my phone on the same wifi.
What do I need to do to make it available across my local network and visible to my phone over wifi?
Here's my Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "10.10.10.10"
config.ssh.forward_agent = true
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", 1024]
v.customize ["modifyvm", :id, "--name", "PHPBoxWith54"]
end
nfs_setting = RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
config.vm.synced_folder "./", "/var/www", id: "vagrant-root" , :nfs => nfs_setting
config.vm.provision :shell, :inline =>
"if [[ ! -f /apt-get-run ]]; then sudo apt-get update && sudo touch /apt-get-run; fi"
config.vm.provision :shell, :inline => 'echo -e "mysql_root_password=root
controluser_password=awesome" > /etc/phpmyadmin.facts;'
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.module_path = "modules"
puppet.options = ['--verbose']
end
end
You are using a Private Network IP which is only accessible by the Host machine (NOT visible to other machines even they are in the same WLAN).
In your case, the best choice is to use Public Network (bridged) so that your Android device can access it.
add config.vm.network "public_network" in your Vagrant file in the config block.
BTW: the default NAT mode is fine but you'll have to set proper port forwarding rules for each service you want to access (e.g. SSH, HTTP, HTTPS etc...).
A little expansion on the accepted answer:
after adding the public network option in your vagrant file and reloading it, ssh into it the old way and then run ifconfig to get the IP you can use to access the vm in your local network from any other device.
Docs: https://www.vagrantup.com/docs/networking/public_network.html
You can easily access your Vagrant from any machine on your network, by simply ensuring that the port forwarding rules aren't bound to your localhost (127.0.0.1).
If you're using VirtualBox as your provider, you can change this on the fly, so you can have it be private by default (which is of course more secure), and then you can go change it in VirtualBox while your VM is running to expose the port to other machines on your network (and possibly the internet, so be careful!)
To expose the port:
Start Virtual Box
Select your VM in the left hand side bar
Click Settings | Network | Advanced | Port Forwarding
Find the port you want to expose in the port list
Set it's Host IP to an empty string, and click OK.
The port is now available to other machines on your network, and possibly the internet, so don't do this unless you're positive you're ok with opening up the port!
Of course to revert it, just do the same process and set the Host IP to 127.0.0.1 again.
This can be just a small problem with port forwarding / setting a dmz. Since it's on the same machine; you can interact since it's physically on the same adapter. However if you are trying to access outside of that, you should try tinkering with the ports.

How to enable internet access inside Vagrant?

If I run curl google.com, I can't see the output, only a blank page. My Vagrantfile contains:
Vagrant.configure("2") do |config|
config.vm.box = "trumobi"
#config.vm.box_url = "http://192.168.136.129/package.box"
config.ssh.default.username = "trumobi"
config.vm.network :public_network
config.vm.network :forwarded_port, host: 8000, guest: 8000
end
If you are using Vagrant + VirtualBox + Ubuntu, you might want to add the following block to your VagrantFile:
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
If you are using ubuntu, and you think your firewall is on, here's how you turn off the firewall:
sudo ufw disable
This happens sometimes for me if I switch the host network connection, like disconnecting my laptop Ethernet cable and start using the wireless network.
I found that rebooting the Vagrant vm (vagrant halt, vagrant up) fixes things.
Disabling firewall helped me.
In my CentOS guest box I did:
# sudo service iptables save
# sudo service iptables stop
# sudo chkconfig iptables off
I tried all of the above without success (Vagrant+Virtualbox+Ubuntu 14.04). Virtualbox was showing 'Adapter 1 (NAT): cable disconnected'. Adding the following to my Vagrantfile fixed it:
config.vm.provider 'virtualbox' do |vb|
vb.customize ['modifyvm', :id, '--cableconnected1', 'on']
end
Found here: https://github.com/mitchellh/vagrant/issues/7648

Resources