I have this Vagrantfile. Here I defined the memory to be 2048 for all VMs. But I want my puppet master to have 4096 and agents to have 2048. How to do that?
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
config.vm.define "puppetmaster" do |pm|
pm.vm.box = "centos/7"
pm.vm.network "private_network", ip: "192.168.33.10"
pm.vm.hostname = "puppetmaster"
end
config.vm.define "puppet-agent-centos" do |pac|
pac.vm.box = "centos/7"
pac.vm.network "private_network", ip: "192.168.33.11"
pac.vm.hostname = "centos-agent"
end
config.vm.define "puppet-agent-ubuntu" do |pau|
pau.vm.box = "ubuntu/xenial64"
pau.vm.network "private_network", ip: "192.168.33.12"
pau.vm.hostname = "ubuntu-agent"
end
end
Thanks!
You can easily do that by overriding the value for a specific VM
config.vm.define "puppetmaster" do |pm|
pm.vm.box = "centos/7"
pm.vm.network "private_network", ip: "192.168.33.10"
pm.vm.hostname = "puppetmaster"
pm.vm.provider "virtualbox" do |pmv|
pmv.memory = 4096
end
end
so your whole file becomes
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
config.vm.define "puppetmaster" do |pm|
pm.vm.box = "centos/7"
pm.vm.network "private_network", ip: "192.168.33.10"
pm.vm.hostname = "puppetmaster"
pm.vm.provider "virtualbox" do |pmv|
pmv.memory = 4096
end
end
config.vm.define "puppet-agent-centos" do |pac|
pac.vm.box = "centos/7"
pac.vm.network "private_network", ip: "192.168.33.11"
pac.vm.hostname = "centos-agent"
end
config.vm.define "puppet-agent-ubuntu" do |pau|
pau.vm.box = "ubuntu/xenial64"
pau.vm.network "private_network", ip: "192.168.33.12"
pau.vm.hostname = "ubuntu-agent"
end
end
Related
thanks for taking the time to look at my question.
I've created a Vagrantfile which launches two vm's, an ubuntu and a centos. I've stated in the Vagrantfile the hostname of both vm's but when I run vagrant up they both come up with the same hostname of centos90.
What am I doing wrong here.
Vagrant.configure("2") do |config|
config.vm.define "ub80" do |ub80|
ub80.vm.box = "hashicorp/precise32"
config.vm.hostname = "ubuntu80"
config.vm.network "private_network", ip: "192.168.33.80"
end
config.vm.define "cos90" do |cos90|
cos90.vm.box = "centos/7"
config.vm.hostname = "centos90"
config.vm.network "private_network", ip: "192.168.33.90"
end
me again!
syntax was wrong I was using config.vm.xxx for configurations instead of the name given in the config.vm.define command.
Below is the corect syntax:
Vagrant.configure("2") do |config|
config.vm.define "ub80" do |ub80|
ub80.vm.box = "hashicorp/precise32"
ub80.vm.hostname = "ubuntu80"
ub80.vm.network "private_network", ip: "192.168.33.80"
end
config.vm.define "cos90" do |cos90|
cos90.vm.box = "centos/7"
cos90.vm.hostname = "centos90"
cos90.vm.network "private_network", ip: "192.168.33.90"
end
My Vagrantfile creates three VMs: k8s-master, ndoe-1, and node-2. How can I enforce that k8s-master is fully provisioned before the provisioning for node-1 and nod-2 starts?
Here is my Vagrantfile:
IMAGE_NAME = "generic/ubuntu1804"
N = 2
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.vm.provider "libvirt" do |v|
v.memory = 1024
v.cpus = 2
end
config.vm.define "k8s-master" do |master|
master.vm.box = IMAGE_NAME
master.vm.network "private_network", ip: "192.168.50.10"
master.vm.hostname = "k8s-master"
master.vm.provision "ansible" do |ansible|
ansible.playbook = "kubernetes-setup/master-playbook.yml"
ansible.extra_vars = {
node_ip: "192.168.50.10",
}
ansible.compatibility_mode = "2.0"
end
end
(1..N).each do |i|
config.vm.define "node-#{i}" do |node|
node.vm.box = IMAGE_NAME
node.vm.network "private_network", ip: "192.168.50.#{i + 10}"
node.vm.hostname = "node-#{i}"
node.vm.provision "ansible" do |ansible|
ansible.playbook = "kubernetes-setup/node-playbook.yml"
ansible.extra_vars = {
node_ip: "192.168.50.#{i + 10}",
}
ansible.compatibility_mode = "2.0"
end
end
end
end
The multi-machine documentation mentions outside-in ordering, so I tried putting the for-each loop inside the k8s-master's define-block, but then the nodes are not created at all.
I'm setting up a new Ansible controller and nodes on virtualbox with a Vargrantfile. I continue to get the error:
There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:
/home/vagrant/ansible/Vagrantfile:19: syntax error, unexpected end-of-input, > expecting keyword_end
I'm changing the placement of the "end" keyword over and over, but still getting the same error on different lines. I'm sure this is simple and I'm just missing it, it's been one of those weeks...
Vagrant.configure("2") do |config|
config.vm.define "controller" do |controller|
controller.vm.box = "bento/ubuntu 16.04"
controller.vm.hostname = "controller"
controller.vm.network :private_network, ip: "10.10.10.10"
controller.vm.provider "virtualbox" do |vb|
vb.memory = "256"
end
end
(1..3).each do |i|
config.vm.define "node#{i}" do |node|
node.vm.box = "bento/ubuntu-16.04"
node.vm.hostname = "node#{i}"
node.vm.network :private_network, ip: "10.10.10.1#{i}"
node.vm.provider "virtualbox" do |vb|
vb.memory = "256"
end
end
I should be able to run vagrant up in the terminal and get an output of provisioning controllers/nodes in virtualbox. What am I missing?
You're missing 2 "end"s at the end of the file
Vagrant.configure("2") do |config|
config.vm.define "controller" do |controller|
controller.vm.box = "bento/ubuntu 16.04"
controller.vm.hostname = "controller"
controller.vm.network :private_network, ip: "10.10.10.10"
controller.vm.provider "virtualbox" do |vb|
vb.memory = "256"
end
end
(1..3).each do |i|
config.vm.define "node#{i}" do |node|
node.vm.box = "bento/ubuntu-16.04"
node.vm.hostname = "node#{i}"
node.vm.network :private_network, ip: "10.10.10.1#{i}"
node.vm.provider "virtualbox" do |vb|
vb.memory = "256"
end
end
end
end
How do I tell vagrant to provision based on condition? I am spinning up multi VMs under a loop
Vagrantfile:
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Iterate through entries in YAML file
servers.each do |servers|
config.vm.define servers["name"] do |srv|
srv.vm.hostname = servers["name"] + DOMAIN
srv.vm.box = servers["box"]
srv.vm.network "private_network", ip: servers["ip"]
srv.vm.synced_folder ".", "/data", id: "mapping", disabled: servers["share"]
srv.vm.provider :virtualbox do |vb|
vb.memory = servers["ram"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
end
end
end
I want to add something like this:
servers.each do |servers|
config.vm.define servers["name"] do |srv|
srv.vm.hostname = servers["name"] + DOMAIN
srv.vm.box = servers["box"]
srv.vm.network "private_network", ip: servers["ip"]
srv.vm.synced_folder ".", "/data", id: "mapping", disabled: servers["share"]
srv.vm.provider :virtualbox do |vb|
vb.memory = servers["ram"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
if servers["name"] == "server1"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "#{cookbooks}"
chef.add_recipe "chef_blah::server"
end
else
puts("Skipping it...")
end
end
end
But every time it executes the provision block on all the VMs
That should be srv.vm.provision, i.e. you are defining it on only that server not the root Vagrant config.
I think I found the solution. It was my mistake
instead of:
config.vm.provision :chef_solo do |chef|
I should have used
srv.vm.provision :chef_solo do |chef|
In the srv loop
I have 5 VMs that I spin up using vagrant.
3 load Balancers, and 2 web servers.
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "lb0" do |lb0|
lb0.vm.box = "ubuntu/trusty64"
lb0.vm.hostname = "lb0"
lb0.vm.network :private_network, ip: "10.11.13.50"
end
config.vm.define "lb01" do |lb01|
lb01.vm.box = "ubuntu/trusty64"
lb01.vm.hostname = "lb01"
lb01.vm.network :private_network, ip: "10.11.13.51"
end
config.vm.define "lb02" do |lb02|
lb02.vm.box = "ubuntu/trusty64"
lb02.vm.hostname = "lb02"
lb02.vm.network :private_network, ip: "10.11.13.52"
end
config.vm.define "web01" do |web01|
web01.vm.box = "ubuntu/trusty64"
web01.vm.hostname = "web01"
web01.vm.network :private_network, ip: "10.11.12.53"
end
config.vm.define "web02" do |web02|
web02.vm.box = "ubuntu/trusty64"
web02.vm.hostname = "web02"
web02.vm.network :private_network, ip: "10.11.12.54"
end
end
I just recently updated the IPs of my load balancers from 10.11.12.x --> 10.11.13.x due to the new requirement.
I run vagrant up again, I don't see new IPs updated on my lb0, lb1, and lb2. :( Did I miss anything ?
What do I do to update my existing VMs IP without having to destroy them and recreate them ?
After adjusting the new IP in Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "lb0" do |lb0|
lb0.vm.box = "ubuntu/trusty64"
lb0.vm.hostname = "lb0"
lb0.vm.network :private_network, ip: "10.11.13.50"
end
config.vm.define "lb01" do |lb01|
lb01.vm.box = "ubuntu/trusty64"
lb01.vm.hostname = "lb01"
lb01.vm.network :private_network, ip: "10.11.13.51"
end
config.vm.define "lb02" do |lb02|
lb02.vm.box = "ubuntu/trusty64"
lb02.vm.hostname = "lb02"
lb02.vm.network :private_network, ip: "10.11.13.52"
end
config.vm.define "web01" do |web01|
web01.vm.box = "ubuntu/trusty64"
web01.vm.hostname = "web01"
web01.vm.network :private_network, ip: "10.11.12.53"
end
config.vm.define "web02" do |web02|
web02.vm.box = "ubuntu/trusty64"
web02.vm.hostname = "web02"
web02.vm.network :private_network, ip: "10.11.12.54"
end
end
I've learn that I have to run vagrant reload
Then, I noticed my IP are updated as expected.
This is weird, normally if you change the network configuration from the Vagrantfile, vagrant should update accordingly in your VM.
If you enable something like config.vm.network :private_network, ip: "10.11.13.52" you should see at the end of file /etc/network/interfaces something like
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet static
address 10.11.13.52
netmask 255.255.255.0
#VAGRANT-END
If you do not see your updated IP in the file, change it manually and run sudo /etc/init.d/networking restart to have the new IP available
Update your Vagrantfile with the ip address available and vagrant reload to effect the changes.