Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #57 from Icinga/feature/vagrantfile-refactor
Browse files Browse the repository at this point in the history
Refactor Vagrantfile, use centos/7 box for VirtualBox, require vbguest plugin

Many thanks to @lbetz & @lazyfrosch for the inspirations!

fixes #17
fixes #53
  • Loading branch information
Michael Friedrich authored Apr 22, 2017
2 parents 9d9e9c2 + 6da9a96 commit 37f2386
Show file tree
Hide file tree
Showing 34 changed files with 977 additions and 998 deletions.
235 changes: 146 additions & 89 deletions README.md

Large diffs are not rendered by default.

125 changes: 78 additions & 47 deletions dev/icinga1x-dev/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

VAGRANTFILE_API_VERSION = "2"
VAGRANT_REQUIRED_VERSION = "1.6.5"
VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4"

# Require 1.6.5 at least
if ! defined? Vagrant.require_version
Expand All @@ -14,76 +15,106 @@ else
Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION
end

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

servers = { 'icinga1-dev' => '192.168.33.190'
# inspired by https://github.com/lbetz/vagrant-icinga-book/blob/master/Vagrantfile
nodes = { 'icinga1-dev' => {
:box => 'centos/7',
:mac => '020027000099',
:net => 'icinga1-dev.demo.local',
:hostonly => '192.168.33.190',
:memory => '2048',
:cpu => '2',
:fowarded => {
'443' => '8443',
'80' => '8082',
'22' => '2082'
}
http_port = { 'icinga1-dev' => 8082
}
ssh_port = { 'icinga1-dev' => 2082
}

servers.each do |server_name, server_ip|
config.vm.define server_name do |app_config|
}
}

# network config
app_config.vm.hostname = "#{server_name.to_s}"
#app_config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true
app_config.vm.network :forwarded_port, guest: 22, host: ssh_port[server_name], auto_correct: true
app_config.vm.network :forwarded_port, guest: 80, host: http_port[server_name], auto_correct: true
app_config.vm.network :private_network, ip: "#{server_ip}"

app_config.vm.provision :shell, :path => "manifests/puppet.sh"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
nodes.each_pair do |name, options|
config.vm.define name do |node_config|
node_config.vm.box = options[:box]
node_config.vm.hostname = name
node_config.vm.box_url = options[:url] if options[:url]
if options[:forwarded]
options[:forwarded].each_pair do |guest, local|
node_config.vm.network "forwarded_port", guest: guest, host: local
end
end

# workaround for Vagrant >1.8.4-1.9.1 not bringing up eth1 properly
# https://github.com/mitchellh/vagrant/issues/8096
app_config.vm.provision "shell", inline: "ifup eth1", run: "always"
node_config.vm.network :private_network, ip: options[:hostonly] if options[:hostonly]

# parallels
app_config.vm.provider :parallels do |p, override|
# provider: parallels
node_config.vm.provider :parallels do |p, override|
override.vm.box = "parallels/centos-7.2"
override.vm.boot_timeout = 600

p.name = "Icinga 1: #{server_name.to_s}"

# Update Parallels Tools automatically
p.name = "Icinga 2: #{name.to_s}"
p.update_guest_tools = false

override.vm.boot_timeout = 600
p.linked_clone = true if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new(VAGRANT_REQUIRED_LINKED_CLONE_VERSION)

# Set power consumption mode to "Better Performance"
p.customize ["set", :id, "--longer-battery-life", "off"]

p.memory = 2048
p.cpus = 2
p.memory = options[:memory] if options[:memory]
p.cpus = options[:cpus] if options[:cpus]
end

# virtualbox
app_config.vm.provider :virtualbox do |v, override|
override.vm.box = "centos-71-x64-vbox"
override.vm.box_url = "http://boxes.icinga.com/centos-71-x64-vbox.box"
# provider: virtualbox
node_config.vm.provider :virtualbox do |vb, override|
unless Vagrant.has_plugin?("vagrant-vbguest")
raise 'vagrant-vbguest is not installed! Run "vagrant plugin install vagrant-vbguest"'
end
node_config.vbguest.auto_update = true
vb.linked_clone = true if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new(VAGRANT_REQUIRED_LINKED_CLONE_VERSION)
vb.name = name
vb.gui = options[:gui] if options[:gui]
vb.customize ["modifyvm", :id,
"--groups", "/Icinga Vagrant/" + options[:net],
"--memory", "512",
"--cpus", "1",
"--audio", "none",
"--usb", "on",
"--usbehci", "off",
"--natdnshostresolver1", "on",
#"--nic2", "intnet",
#"--intnet2", options[:net],
#"--macaddress2". options[:mac]
]
vb.memory = options[:memory] if options[:memory]
vb.cpus = options[:cpus] if options[:cpus]
end

v.customize ["modifyvm", :id, "--memory", "2048"]
v.customize ["modifyvm", :id, "--cpus", "2"]
# Using the host's resolver as a DNS proxy in NAT mode
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
# provider: libvirt
node_config.vm.provider :libvirt do |lv, override|
lv.memory = options[:memory] if options[:memory]
lv.cpus = options[:cpus] if options[:cpus]
end

app_config.vm.provider :libvirt do |l, override|
override.vm.box = "centos/7"
# provisioner: ensure that hostonly network is up
#
# workaround for Vagrant >1.8.4-1.9.1 not bringing up eth1 properly
# https://github.com/mitchellh/vagrant/issues/8096
node_config.vm.provision "shell", inline: "service network restart", run: "always"

l.memory = 2048
l.cpus = 2
end
# provisioner: install requirements
node_config.vm.provision :shell, :path => "../../scripts/shell_provisioner.sh" # icinga1x-dev specific modification

# provisioner
app_config.vm.provision :puppet do |puppet|
puppet.module_path = "../../modules" #we're located in ./dev not main tree
# provisioner: install box using puppet manifest
node_config.vm.provision :puppet do |puppet|
puppet.module_path = "../../modules" # icinga1x-dev specific modification
puppet.manifests_path = "manifests"
puppet.hiera_config_path = "hiera.yaml"
#puppet.options = "--verbose --debug --parser=future"
puppet.options = "--parser=future"
end
app_config.vm.provision :shell, :path => "manifests/finalize.sh"

# print a friendly message
node_config.vm.provision "shell", inline: <<-SHELL
echo "Finished installing the Vagrant box '#{name}'."
echo "Navigate to http://#{options[:hostonly]}"
SHELL
end
end
end
Expand Down
File renamed without changes.
File renamed without changes.
144 changes: 144 additions & 0 deletions dev/icinga2x-freebsd/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"
VAGRANT_REQUIRED_VERSION = "1.6.5"
VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4"

# Require 1.6.5 at least
if ! defined? Vagrant.require_version
if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(VAGRANT_REQUIRED_VERSION)
puts "Vagrant >= " + VAGRANT_REQUIRED_VERSION + " required. Your version is " + Vagrant::VERSION
exit 1
end
else
Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION
end

# inspired by https://github.com/lbetz/vagrant-icinga-book/blob/master/Vagrantfile
nodes = { 'icinga2-freebsd' => {
:box => 'freebsd/FreeBSD-11.0-STABLE',
:mac => '080027D14C66',
:net => 'icinga2-freebsd.demo.local',
:hostonly => '192.168.33.9',
:memory => '2048',
:cpu => '2',
:fowarded => {
'443' => '8443',
'80' => '8082',
'22' => '2082'
}
}
}

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
nodes.each_pair do |name, options|
config.vm.define name do |node_config|
node_config.vm.box = options[:box]
node_config.vm.hostname = name
node_config.vm.box_url = options[:url] if options[:url]
if options[:forwarded]
options[:forwarded].each_pair do |guest, local|
node_config.vm.network "forwarded_port", guest: guest, host: local
end
end

#node_config.vm.network :private_network, ip: options[:hostonly] if options[:hostonly]

# FreeBSD specific modifications
node_config.vm.base_mac = "080027D14C66"
node_config.vm.guest = :freebsd
node_config.vm.synced_folder ".", "/vagrant", disabled: true
node_config.ssh.shell = "bash"

# provider: parallels
#node_config.vm.provider :parallels do |p, override|
# override.vm.box = "parallels/centos-7.2"
# override.vm.boot_timeout = 600

# p.name = "Icinga 2: #{name.to_s}"
# p.update_guest_tools = false
# p.linked_clone = true if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new(VAGRANT_REQUIRED_LINKED_CLONE_VERSION)

# # Set power consumption mode to "Better Performance"
# p.customize ["set", :id, "--longer-battery-life", "off"]

# p.memory = options[:memory] if options[:memory]
# p.cpus = options[:cpus] if options[:cpus]
#end

# provider: virtualbox
node_config.vm.provider :virtualbox do |vb, override|
#unless Vagrant.has_plugin?("vagrant-vbguest")
# raise 'vagrant-vbguest is not installed! Run "vagrant plugin install vagrant-vbguest"'
#end
#node_config.vbguest.auto_update = true
#vb.linked_clone = true if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new(VAGRANT_REQUIRED_LINKED_CLONE_VERSION)
vb.name = name
vb.gui = options[:gui] if options[:gui]

# FreeBSD specific modifications
vb.customize ["modifyvm", :id,
"--groups", "/Icinga Vagrant/" + options[:net],
"--memory", "2048",
"--cpus", "2",
"--natdnshostresolver1", "on",
"--hwvirtex", "on",
"--nictype1", "virtio",
"--nictype2", "virtio",
#"--audio", "none",
#"--usb", "on",
#"--usbehci", "off",
#"--nic2", "intnet",
#"--intnet2", options[:net],
#"--macaddress2". options[:mac]
]
#vb.memory = options[:memory] if options[:memory]
#vb.cpus = options[:cpus] if options[:cpus]
end

# provider: libvirt
#node_config.vm.provider :libvirt do |lv, override|
# lv.memory = options[:memory] if options[:memory]
# lv.cpus = options[:cpus] if options[:cpus]
#end

# provisioner: ensure that hostonly network is up
#
# workaround for Vagrant >1.8.4-1.9.1 not bringing up eth1 properly
# https://github.com/mitchellh/vagrant/issues/8096
#node_config.vm.provision "shell", inline: "service network restart", run: "always"

# provisioner: install requirements
#node_config.vm.provision :shell, :path => "../scripts/shell_provisioner.sh"

# provisioner: install box using puppet manifest
#node_config.vm.provision :puppet do |puppet|
# puppet.module_path = "../modules"
# puppet.manifests_path = "manifests"
# puppet.hiera_config_path = "hiera.yaml"
# #puppet.options = "--verbose --debug --parser=future"
# puppet.options = "--parser=future"
#end

# print a friendly message
#node_config.vm.provision "shell", inline: <<-SHELL
# echo "Finished installing the Vagrant box '#{name}'."
# echo "Navigate to http://#{options[:hostonly]}"
#SHELL
# FreeBSD specific modifications
node_config.vm.provision "shell", inline: <<-SHELL
env ASSUME_ALWAYS_YES=YES pkg install icinga2 wget curl gdb vim python
sysrc icinga2_enable=yes
icinga2 api setup
echo 'object ApiUser "root" {' >/usr/local/etc/icinga2/conf.d/api-users.conf
echo ' password = "icinga"' >>/usr/local/etc/icinga2/conf.d/api-users.conf
echo ' permissions = [ "*" ]' >>/usr/local/etc/icinga2/conf.d/api-users.conf
echo '}' >>/usr/local/etc/icinga2/conf.d/api-users.conf
service icinga2 restart
echo "Finished installing the Vagrant box '#{name}'."
SHELL
end
end
end

Loading

0 comments on commit 37f2386

Please sign in to comment.