I have the following problem. I need a Vagrant file to create:
3 Ubuntu 18.04 hosts;
1 Ubuntu 16.04 host.
I have the following Vagrant file:
require 'yaml'
# Load settings from servers.yml file.
environment = YAML.load_file('env.yaml')
...
Vagrant.configure("2") do |config|
environment["servers"].each do |server|
config.vm.define server["name"] do |srv_config|
srv_config.vm.box = server["box"]
srv_config.ssh.insert_key = false
srv_config.vm.hostname = server["name"]
srv_config.vm.network :private_network, ip: server["eth1"]
srv_config.vm.provider "virtualbox" do |v|
v.name = server["name"]
v.customize ["modifyvm", :id, "--groups", "/Development"]
v.customize ["modifyvm", :id, "--memory", server["mem"]]
v.customize ["modifyvm", :id, "--cpus", server["cpu"]]
end
srv_config.vm.provision "file" ...
end
end
end
Now I want that this Vagrant file get the servers configuration (OS, CPU, Memory, IP, etc.) from an external env.yml file like this:
servers:
- name: node-0
box: generic/ubuntu1804
eth1: 192.168.20.101
mem: 1024
cpu: 1
- name: node-1
box: generic/ubuntu1804
eth1: 192.168.20.102
mem: 1024
cpu: 1
- name: node-2
box: generic/ubuntu1804
eth1: 192.168.20.103
mem: 1024
cpu: 1
- name: legacy
box: generic/ubuntu1604
eth1: 192.168.20.105
mem: 1024
cpu: 1
My problem is that I don't know why the nodes are created with:
node-0 with Ubuntu 16.04 instead of 18.04 <-- WHY????
node-1 with Ubuntu 18.04 (this is correct)
node-2 with Ubuntu 18.04 (this is correct)
legacy with Ubuntu 16.04 (this is correct)
As you can understand my main problem is that node-0 is created with Ubuntu 16.04 and not Ubuntu 18.04. Why? I debugged the code and for srv_config.vm.box for node-0 the value is generic/ubuntu1804. Moreover, I correctly see 1 CPU and 1 Gb RAM for each machine, but in Virtual Box I don't see the machines in the group Development.
Anyone can help me to understand why these problems?
I think I figure out the issue. The file is correct, the problem was the Vagrant cache. I removed the .vagrant folder and run again vagrant up.
Related
I am trying to do vagrant up for a CentOS 8 machine I have built using Jeff Geerling's packer-boxes repo.
My Vagrantfile looks like this.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.vm.synced_folder '.', '/vagrant', type: 'nfs'
# VirtualBox.
config.vm.define "virtualbox" do |virtualbox|
virtualbox.vm.hostname = "virtualbox-centos8"
virtualbox.vm.box = "file://builds/virtualbox-centos8.box"
virtualbox.vm.network :private_network, ip: "172.16.9.29"
virtualbox.vbguest.auto_update = true
config.vm.provider :virtualbox do |v| v.gui = false
v.memory = 1024
v.cpus = 1
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--ioapic", "on"]
end
config.vm.provision "shell", inline: "echo Hello, World"
end
end
I get this error message that it cannot use NFS.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o vers=3 172.16.9.1:/home/bcrice/projects/packer-boxes/centos8 /vagrant
Stdout from the command:
Stderr from the command:
mount.nfs: requested NFS version or transport protocol is not supported
I have tried all the tricks posted here but none worked.
https://github.com/hashicorp/vagrant/issues/9666
I am using this version of Ubuntu desktop
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"
VirtualBox on my host
dpkg -l | grep virtualbox | awk '{print $3}'
6.1.10-dfsg-1~ubuntu1.20.04.1
6.1.10-dfsg-1~ubuntu1.20.04.1
6.1.10-1~ubuntu1.20.04.1
6.1.10-dfsg-1~ubuntu1.20.04.1
Guest in VirtualBox says it is running the guest-utils
vagrant vbguest --status
[virtualbox] GuestAdditions 6.1.10 running --- OK.
My /etc/exports auto-adds the entry properly but it doesn't work
cat /etc/exports
# VAGRANT-BEGIN: 1000 2b82110e-78ed-489e-891e-c80e073c4f73
"/home/bcrice/packer-boxes/centos8" 172.16.9.29(rw,no_subtree_check,all_squash,anonuid=1000,anongid=1000,fsid=187307313)
# VAGRANT-END: 1000 2b82110e-78ed-489e-891e-c80e073c4f73
Needed to do apt install nfs-kernel-server. Even though systemctl status nfs-kernel-server said it was running, it was not actually installed. Once installed do a systemctl restart nfs-kernel-server and it worked.
A nice giveaway was that when I ran exportfs it said that nfs-kernel-server was not installed.
Run dpkg -l | grep nfs-kernel-server and double-check to see if you have it installed.
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"
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
I realize this is essentially OSCeption (Operating System Inception), but I think it might make the most sense for me (please tell me if there's a better option, this seems really awful).
Here's the situation:
I have a windows 8 machine. I like it - it works great for everything but development. For development, I've been using a VMWare virtual machine running Ubuntu. I've dabbled with using Cygwin, but it just didn't feel right.
I'm now joining a project where they've been using Vagrant to manage development environments so I need to be able to use Vagrant. But, from what I've seen, Vagrant is mainly used to run code within a consistent environment, but not necessarily to write it. And if I wanted to write code by SSH'ing into my vagrant boxes, then I would have to re-configure my preferences like my .vimrc file and what not for every machine.
Does it then make sense to install Vagrant within my Ubuntu VirtualMachine? I feel like at some point VMs within VMs will get out of hand and cause problems. Is there any better way to do this?
Edit: So I tried it out - as I expected I hit some errors. When I try and boot the machine, I get the following error message:
Failed to open a session for the virtual machine vagranttest_1371583212.
VT-x is not available. (VERR_VMX_NO_VMX).
Result Code: NS_ERROR_FAILURE (0x80004005)
Component: Console
Interface: IConsole {db7ab4ca-2a3f-4183-9243-c1208da92392}
Looks like my vmware virtual machine can't run another virtual machine. Any ideas on the best way to go about doing this?
I've run into the same issue today. The solution is quite simple.
Power off vmware vitrual machine.
Go to "edit virtual machine settings"
Go to processors. There are three checkboxes there.
Check second checkbox (enable VT-x/AMD-V)
Power on machine.
After this virtualbox should work inside vmware.
To answer the original question as well as #blong's Vagrant forum post, this is what I've done to make this work.
I was trying to do something similar myself (actually Vagrant/VMware hosting Vagrant/Vbox) and I have performed all the optimizations I can think of, giving my "host" VM a large amount of RAM (24GB) and 6 cores, disabling swapping VMs to disk (this KILLS things on Windows when it happens) by setting "Fit all VM memory into reserved host memory", and allowing per VM page files (otherwise they live in the system page file which limits how many VMs you can run at once).
What I am doing has been working perfectly, the networking issues I've had were due to the corporate proxy I'm behind. Once I configured that my VM got internet access and all was right with the world.
I did have to manually set --natbindip1 and --natnet1 via the Vagrantfile in addition to the natdnsproxy1 and naddnshostresolver1 that were already set in my example (Virtualbox) Vagrantfile. These settings can be found in the Virtualbox documentation for the correct usage.
To sum it up, use the VT-x passthrough/"virtualize" option in your VM CPU settings, give the VM adequate memory, don't allow that memory to be swapped on the "root" host machine, and try to make sure your network ranges don't overlap or you'll have routing trouble.
Here is the Vagrantfile I was working from, it is based almost entirely on andreptb's gist for the modern.ie vagrant setup. https://gist.github.com/andreptb/57e388df5e881937e62a
# -*- mode: ruby -*-
# vi: set ft=ruby :
# box name into env var, same script can be used with different boxes. Defaults to win7-ie11.
box_name = box_name = ENV['box_name'] != nil ? ENV['box_name'].strip : 'win7-ie11'
# box repo into env var, so private repos/cache can be used. Defaults to http://aka.ms
box_repo = ENV['box_repo'] != nil ? ENV['box_repo'].strip : 'http://aka.ms'
Vagrant.configure("2") do |config|
# If the box is win7-ie11, the convention for the box name is modern.ie/win7-ie11
config.vm.box = "modern.ie/" + box_name
# If the box is win7-ie11, the convention for the box url is http://aka.ms/vagrant-win7-ie11
config.vm.box_url = box_repo + "/vagrant-" + box_name
# big timeout since windows boot is very slow
config.vm.boot_timeout = 500
# rdp forward
config.vm.network "forwarded_port", guest: 3389, host: 3389, id: "rdp", auto_correct: true
# winrm config, uses modern.ie default user/password. If other credentials are used must be changed here
config.vm.communicator = "winrm"
config.winrm.username = "IEUser"
config.winrm.password = "Passw0rd!"
config.vm.provider "virtualbox" do |vb|
# first setup requires gui to be enabled so scripts can be executed in virtualbox guest screen
#vb.gui = true
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--vram", "128"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
end
end
My additional changes:
# Need the WinRM gem for managing from Linux
$ sudo gem install winrm
config.vm.communicator = "winrm"
+ config.winrm.host = "localhost"
config.winrm.username = "IEUser"
config.winrm.password = "Passw0rd!"
# This one may not be necessary, I added it for completeness
+ config.vm.guest = :windows
# In order to USE the two CPUs you need the ioapic
# Virtualbox gives an error in the GUI and only shows 1 CPU in the VM otherwise
vb.customize ["modifyvm", :id, "--cpus", "2"]
+ vb.customize ["modifyvm", :id, "--ioapic", "on"]
# We had to modify the network range because we are running Virtualbox inside VMware
+ vb.customize ["modifyvm", :id, "--natnet1", "192.168.199.0/24"]
Remove the + signs and add those lines into the Vagrantfile above and you should have an equivalent working system to what I've been using.
If you are running virualbox in a VM in vsphere, you have to ssh to the ESXi to update a configuration.
Steps:
ssh to ESXi server.
find the vmx file which belong to your VM find / -name *.vmx
poweroff your VM.(very important, or your change will be overwrite)
edit that vmx, append a new configuration at the bottom of the file: vhv.enable = "TRUE"
power on your VM
enjoy the Vagrant. :)
I have tried this in two VMware products. Right-click on the VM:
In vCloud Director 5.5 VM properties on the Hardware tab there's an "Expose hardware-assisted CPU virtualization to guest OS" checkbox, but it's grayed out for me. YMMV.
In vSphere Version 5.5.0 Edit Settings > Virtual Hardware > CPU the checkbox is called "Expose hardware assisted virtualization to the guest OS," and that worked for me.
On Windows 7 64 bit trying to start up a VM (Ubuntu 32 bit). I'm having trouble getting my VM to show two cores despite adding the modify vm command in my Vagrantfile. My Vagrant version is 1.2.2.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
end
end
With this Vagrantfile I issue the vagrant up command. Then I issue vagrant ssh followed by lscpu which yields:
Architecture: i686
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 58
Stepping: 9
CPU MHz: 2565.513
BogoMIPS: 5131.02
L1d cache: 32K
L1d cache: 32K
L2d cache: 6144K
I think CPU(s) should show 2, so my VM only has one CPU right now. How can I get 2 CPUs to show up when I run lscpu?
Add vb.customize ["modifyvm", :id, "--ioapic", "on"] to the config.vm.provider block inside your Vagrantfile.
Looking at the VirtualBox documentation it mentions:
"Note Enabling the I/O APIC is required for 64-bit guest operating
systems, especially Windows Vista; it is also required if you want to
use more than one virtual CPU in a virtual machine."
If you are running vagrant using Oracle Virtualbox then the most common issue is with Hyper-V in Windows 7, 8 or 10. That will limit you to 32bit and one cpu.
Run or search for "Windows Features" and select "Turn Windows Features On or Off".
In the checkboxes make sure Hyper-V is off - you can't enable VT-x for Virtualbox with Microsoft Hyper-V hogging it.
Then, you can make your Vagrantfile boot very user friendly with:
config.vm.provider "virtualbox" do |vb|
vb.memory = "2404"
vb.cpus = "2"
end
Assuming you want to have two cores running and just a bit over 2 Gig of memory
ps - don't forget to add your port forwarding. For PHPStorm (xdebug, mysql, and web) I use:
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 3306, host: 3306
config.vm.network "forwarded_port", guest: 9000, host: 9000
It seems you have not mentioned which provider you are using. As of Vagrant 1.7 many VM providers (such as VirtualBox, HyperV) supports the following configuration in your Vagrantfile:
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 2
end
Check out the specific provider you are using in the vagrant documentation.