Vagrant - The following settings shouldn't exist: memory, name - vagrant

I have moved this question over from Serverfault I thought it was more of a question belonging there :-)
I have Vagrant version 1.9.1 on macOS and I have VirtualBox 5.1.12
I am trying to have a go at creating a multi machine Vagrant file and I am running into trouble when I want to run it.
I get the message:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* The following settings shouldn't exist: memory, name
Now at this stage I have commented out the second machine, because I get the error twice - so I am just trying to fix the first one.
I have seen on other threads I should remove the .vm in the lines that are in the "web" block, but if I do that then I get this error:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
Vagrant:
* Unknown configuration section 'memory='.
* Unknown configuration section 'name='.
* Unknown configuration section 'network'.
* Unknown configuration section 'provision'.
I am at a bit of a loss here, because the answers I am getting make sense in theory and I started this from the vagrant up docs, but somehow in my case I can't get it running.
My vagrant file is right here - so please any help would be appreciated :-)
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
end
config.vm.define "web" do |web|
web.vm.name = "16.04-web01"
web.vm.memory = "512"
web.vm.network "private_network", ip: "192.168.50.3"
web.vm.network "forwarded_port", guest: 80, host: 8083
web.vm.network "public_network", bridge: "en1: Wi-Fi (AirPort)"
web.vm.provision :shell, path: "bootstrap.sh"
end
# config.vm.define :sql01 do |sql|
# sql.vm.name = "16.04-sqlserver"
# sql.vm.memory = "4096"
# sql.vm.network "private_network", ip: "192.168.50.2"
# sql.vm.network "forwarded_port", guest: 80, host: 8084
# sql.vm.network "public_network", bridge: "en1: Wi-Fi (AirPort)"
# sql.vm.provision :shell, path: "bootstrap.sh"
# end
#Options for Me specific
config.vm.synced_folder "/Applications/MAMP/htdocs/", "/htdocs_home"
end

name and memory are provider specific parameters so they need to be moved in this block
Vagrant.configure("2") do |config|
config.vm.box = "geerlingguy/ubuntu1604"
config.vm.define "web" do |web|
web.vm.network "private_network", ip: "192.168.50.3"
web.vm.network "forwarded_port", guest: 80, host: 8083
web.vm.network "public_network", bridge: "en1: Wi-Fi (AirPort)"
web.vm.provision :shell, path: "bootstrap.sh"
web.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.name = "16.04-web01"
vb.memory = "512"
end
end
config.vm.define :sql01 do |sql|
sql.vm.network "private_network", ip: "192.168.50.2"
sql.vm.network "forwarded_port", guest: 80, host: 8084
sql.vm.network "public_network", bridge: "en1: Wi-Fi (AirPort)"
sql.vm.provision :shell, path: "bootstrap.sh"
sql.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.name = "16.04-sqlserver"
vb.memory = "4096"
end
end
#Options for Me specific
config.vm.synced_folder "/Applications/MAMP/htdocs/", "/htdocs_home"
end

Related

Strange behaviour of Vagrant Up command

Whenever I run Vagrant up, I am getting the following error.
Following is my vagrant file
default_box = "generic/opensuse42"
Vagrant.configure("2") do |config|
config.vm.define "master" do |master|
master.vm.box = default_box
master.vm.box_version = "v3.4.4"
master.vm.hostname = "master"
master.vm.network 'private_network', ip: "192.168.0.200", virtualbox__intnet: true
master.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh", disabled: true
master.vm.network "forwarded_port", guest: 22, host: 2000 # Master Node SSH
master.vm.network "forwarded_port", guest: 6443, host: 6443 # API Access
for p in 30000..30100 # expose NodePort IP's
master.vm.network "forwarded_port", guest: p, host: p, protocol: "tcp"
end
master.vm.provider "virtualbox" do |v|
v.memory = "3072"
v.name = "master"
end
master.vm.provision "shell", inline: <<-SHELL
sudo zypper refresh
sudo zypper --non-interactive install bzip2
sudo zypper --non-interactive install etcd
sudo zypper --non-interactive install apparmor-parser
curl -sfL https://get.k3s.io | sh -
SHELL
end
Any hints will be much appreciated.
The error message provides the info you require:
in 'parse': Illformed requirement ["v3.4.4"] (Gem::Requirement::BadRequirementError)
It basically advises that there is a problem with your version of vm requested from your Vagrantfile:
default_box = "generic/opensuse42"
Vagrant.configure("2") do |config|
config.vm.define "master" do |master|
master.vm.box = default_box
master.vm.box_version = "v3.4.4"
master.vm.hostname = "master"
The problem is that you have used 'v' to define the version, which cannot be parsed for the value attained for the 'config.vm.box_version' attribute variable - it should be :
master.vm.box_version = "3.4.4"
You can always double check your config for a vm from the Vagrant website, in your case generic/opensuse42 - v3.4.4, it shows that it should be:
Vagrant.configure("2") do |config|
config.vm.box = "generic/opensuse42"
config.vm.box_version = "3.4.4"
end
I found that generic/opensuse42 has been expired so changing the box to opensuse/Leap-15.2.x86_64, solved my issue

vagrant ansible access other machines IP address

I have a vagrant file to create 3 VMs and an ansible to manage these 3 machines (inventory file is generated by the vagrant file). I need to access the VM no.1 IP address in order to put it in the configuration file of two other machines. but using hostvars[vm1] variable won't give me the IP address of the vm1.
Here is my vagrant file:
Vagrant.configure("2") do |config|
config.vm.network "private_network", type: "dhcp"
config.vm.provider "virtualbox" do |v|
v.memory = 512
end
config.vm.synced_folder ".", "/vagrant"
config.vm.box_check_update = false
config.vm.define "vm1" do |vm1|
vm1.vm.box = "hashicorp/bionic64"
end
config.vm.define "vm2" do |vm2|
vm2.vm.box = "hashicorp/bionic64"
end
config.vm.define "vm3" do |vm3|
vm3.vm.box = "hashicorp/bionic64"
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
#ansible.ask_become_pass = true
ansible.groups = {
"node_master" => ["vm1"],
"node_replicas" => ["vm2", "vm3"],
"node:children" => ["node_master", "node_replicas"]
}
end
How can I solve this problem?
As configured, your ansible provisionner will run three times: once independently for each machine, being called with a limit set to the current machine name.
In this situation, the facts for all other machines will not be gathered in your playbook and hostvars[vm1] will be empty (unless you are currently running on vm1).
What you can try is to declare the provisionner on a single machine only (the best bet being vm3, the last one) and change the default current machine limit to all
config.vm.define "vm3" do |vm3|
vm3.vm.box = "hashicorp/bionic64"
vm3.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.limit = "all"
#ansible.ask_become_pass = true
ansible.groups = {
"node_master" => ["vm1"],
"node_replicas" => ["vm2", "vm3"],
"node:children" => ["node_master", "node_replicas"]
}
end
end
This way, your playbook will run on all your vms at once in parallel and you should be able to access facts from all the hosts you target in your playbook.
I got no clue how to solve your specific version.
However, I use Vagrant and Ansible separately. Vagrant to only build the hosts with vagrant up, and Ansible to manage the configuration on those hosts.
I use this Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 1
end
config.ssh.insert_key = false
config.vm.define "multi-1" do | localMulti1 |
localMulti1.vm.box = "ubuntu/xenial64"
localMulti1.vm.hostname = "multi-1"
localMulti1.vm.network :forwarded_port, guest: 22, host: 30001, id: "ssh"
localMulti1.vm.network "private_network", ip: "10.0.0.111"
end
config.vm.define "multi-2" do | localMulti2 |
localMulti2.vm.box = "ubuntu/xenial64"
localMulti2.vm.hostname = "multi-2"
localMulti2.vm.network :forwarded_port, guest: 22, host: 30002, id: "ssh"
localMulti2.vm.network "private_network", ip: "10.0.0.112"
end
config.vm.define "multi-3" do | localMulti3 |
localMulti3.vm.box = "ubuntu/xenial64"
localMulti3.vm.hostname = "multi-3"
localMulti3.vm.network :forwarded_port, guest: 22, host: 30003, id: "ssh"
localMulti3.vm.network "private_network", ip: "10.0.0.113"
localMulti3.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.inventory_path = "inventory"
ansible.limit = "local_multi"
end
end
end
I place this in my inventory file:
[local_multi]
multi-1 ansible_ssh_user=vagrant ansible_host=127.0.0.1 ansible_ssh_port=30001 ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
multi-2 ansible_ssh_user=vagrant ansible_host=127.0.0.1 ansible_ssh_port=30002 ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
multi-3 ansible_ssh_user=vagrant ansible_host=127.0.0.1 ansible_ssh_port=30003 ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
Your playbook.yml
---
- hosts: local_multi
become: True
tasks:
- name: check who is master
debug:
msg: "{{ node_master }}"
when: node_master is defined
Now you can place all your Ansible vars in the grouped or host vars;
./inventory
./playbook.yml
./Vagrantfile
./group_vars/all.yml
./host_vars/multi-1.yml
./host_vars/multi-2.yml
./host_vars/multi-3.yml

Strange vagrant shared folder issue -> can not "rm -rf"

My Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |v|
v.name = "web_vm"
v.customize ["modifyvm", :id, "--memory", "1024"]
#v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/web_vm", "1"]
end
config.vm.box = "ubuntu/trusty64"
config.vm.network :forwarded_port, host: 81, guest: 80, auto_correct: true
config.vm.network :forwarded_port, host: 6612, guest: 3306, auto_correct: true
config.vm.synced_folder "src/", "/var/www", owner: "vagrant", group: "vagrant", :mount_options => ["dmode=777,fmode=777"]
config.vm.provision :shell, path: "bootstrap.sh"
end
As you can see, The "src" folder is accessible in vagrant as "/var/www". However, there seem to be sync problems: I am trying to remove a folder which is shown empty where it is not when you cross-check with the Windows Explorer.
Any idea what is happening here?
I have the same issue, but it seemed to be resolved by increasing the max_user_watches - variable for inotify:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
My guess was that this had to to with the amount of files in the shared folder, and how vagrant has implemented the shared folder functionality.

Vagrant complaints about "customize"

I'm having a weird problem with Vagrant. Changing the default RAM of the virtual machine would have to be easy but I don't know why I am not able to do it.
My code is very simple:
# -*- 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|
config.vm.define "mimeticStack" do |v|
v.vm.box = "precise64"
v.vm.box_url = "http://files.vagrantup.com/precise64.box"
v.vm.network "private_network", ip: "192.168.33.10"
v.vm.network "forwarded_port", guest: 80, host: 8080
v.vm.hostname = "dev.mimetic.local"
v.vm.customize ["modifyvm", :id, "--memory", "512"]
end
end
Then if I run "vagrant up", Vagrant returns:
vm:
* The following settings shouldn't exist: customize
The issue was fixed:
# -*- 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|
config.vm.define "mimeticStack" do |v|
v.vm.box = "precise64"
v.vm.box_url = "http://files.vagrantup.com/precise64.box"
v.vm.network "private_network", ip: "192.168.33.10"
v.vm.network "forwarded_port", guest: 80, host: 8080
v.vm.hostname = "dev.mimetic.local"
v.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id,'--memory', '512']
end
end
end
I left the code here for Vagrant beginners like me.
I have tried #MikeD's suggestion with
config.vm.provider "virtualbox" do |vb|
vb.memory = "<some size>"
vb.cpus = "<some number>"
end
and it works as expected. I can ssh into my vagrant box and run lscpu and cat /proc/meminfo which give me the values I specified above.

Issue with hanging vagrant up on win7 while configuring network adapter

Vagrant version: 1.4.0
vagrant-windows version: 1.5.1
Vagrant file:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "win7.x86.v.004"
config.vm.box_url = "URL"
config.vm.boot_timeout = 300
config.vm.provider :virtualbox do |vb|
vb.gui = true
end
config.windows.halt_timeout = 15
config.winrm.username = "vagrant"
config.winrm.password = "vagrant"
config.vm.guest = :windows
config.vm.network :forwarded_port, guest: 5985, host: 5685, id: "winrm", :auto => true
config.vm.network :forwarded_port, guest: 5986, host: 5686
config.vm.network :forwarded_port, guest: 8080, host: 5687
config.vm.network :forwarded_port, guest: 1521, host: 5688
config.winrm.host = "192.168.33.33"
config.winrm.port = 5985
config.windows.set_work_network = true
config.vm.network :private_network, ip: "192.168.33.33"
config.vm.provision :shell, :path => "provision.bat"
end
I am using selfcreated Win7 enterprise SP1 box
vagrant up hangs on configuring network adapter, debug logs here:
DEBUG configure_networks: vm_interface_map: {1=>{:net_connection_id=>"Local Area
Connection", :mac_address=>"08002753776B", :interface_index=>"11", :index=>"7"}
, 2=>{:net_connection_id=>"Local Area Connection 2", :mac_address=>"080027F5E843
", :interface_index=>"14", :index=>"12"}}
INFO winrmshell: Configuring NIC Local Area Connection 2 using static ip 192.16
8.33.33
DEBUG winrmshell: powershell executing:
netsh interface ip set address "Local Area Connection 2" static 192.168.33.33 25
5.255.255.0
After "netsh" command execution hangs.
Any workaround of how I can resolve this?
found solution, in my VagrantFile there wrong
config.winrm.host = "192.168.33.33"
this shoult be host IP address, but i used guest IP, thats why while executing netsh command "vagrant up" silently hungs.
Reason is that netsh command resets network interface and vagrant can not get result of netsh comand.
mainly, this parametr should not be set or set to 127.0.0.1

Resources