Following is a sample Vagrantfile that will start 4 vagrant box and assigning each an public ipaddress and puppet class, where we can define what all need to deployed on there box. Over here I have provided one vagrant_box image, but if you want you can provide each host with different vagrant_box_image.
$cat Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "vg2" do |vg2|
vg2.vm.box = "my_vagrant_image"
vg2.vm.hostname = "vg2"
vg2.vm.network "public_network", :bridge => 'wlan0', :ip => "192.168.0.32"
end
config.vm.define "vg3" do |vg3|
vg3.vm.box = "my_vagrant_image"
vg3.vm.hostname = "vg3"
vg3.vm.network "public_network", :bridge => 'wlan0', :ip => "192.168.0.33"
end
config.vm.define "vg4" do |vg4|
vg4.vm.box = "my_vagrant_image.box"
vg4.vm.hostname = "vg4"
vg4.vm.network "public_network", :bridge => 'wlan0', :ip => "192.168.0.34"
end
config.vm.define "vg5" do |vg5|
vg5.vm.box = "my_vagrant_image.box"
vg5.vm.hostname = "vg5"
vg5.vm.network "public_network", :bridge => 'wlan0', :ip => "192.168.0.35"
end
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "default.pp"
puppet.options = ['--verbose']
end
explanation of puppet class:
Note: even if we have lots of different vagrant box defined in a single Vagrantfile, we just need to have only one puppet class, that should be enough for all of the vagrant box.
puppet.manifests_path = "puppet/manifests"
The above line says what is the path where we have the manifests file. [ Relative to the location where we have the Vagrantfile. ]
puppet.manifest_file = "default.pp"
The above line says which is the manifest file.
Example of the manifest.pp:
$ cat puppet/manifests/default.pp
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
class system-update {
exec { 'apt-get update':
command => 'apt-get update',
}
$sysPackages = [ "build-essential" ]
package { $sysPackages:
ensure => "installed",
require => Exec['apt-get update'],
}
}
class apache {
package { "apache2":
ensure => present,
require => Class["system-update"],
}
service { "apache2":
ensure => "running",
require => Package["apache2"],
}
}
class iotop {
package { "iotop":
ensure => present,
require => Class["system-update"],
}
}
include apache
include system-update
include iotop
NOTE: you have to use the include lines for deploying those package to these instance. Note: Example the iotop class also have a require => Class, pointing to the system-update class. If you don't what to have the system-update class run at your system then, you can comment these line [with # ] and comment the following include line too.
No comments:
Post a Comment