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

Commit

Permalink
icinga2x-ha-cluster: Refactor Vagrantfile
Browse files Browse the repository at this point in the history
refs #17
refs #53
  • Loading branch information
Michael Friedrich committed Apr 22, 2017
1 parent dc4c185 commit 768ddd8
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 89 deletions.
163 changes: 105 additions & 58 deletions icinga2x-ha-cluster/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,86 +15,132 @@ else
Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION
end

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# ip addresses are used in /etc/icinga2/cluster/cluster.conf (!)
servers = { 'icinga2a' => '192.168.33.101',
'icinga2b' => '192.168.33.102',
'icinga2c' => '192.168.33.103'
# inspired by https://github.com/lbetz/vagrant-icinga-book/blob/master/Vagrantfile
nodes = { 'icinga2a' => {
:box => 'centos/7',
:mac => '020027000102',
:net => 'icinga2a.demo.local',
:hostonly => '192.168.33.101',
:memory => '1024',
:cpu => '1',
:fowarded => {
'443' => '8445',
'80' => '8085',
'22' => '2085'
}
http_port = { 'icinga2a' => 8085,
'icinga2b' => 8086,
'icinga2c' => 8087
}
ssh_port = { 'icinga2a' => 2085,
'icinga2b' => 2086,
'icinga2c' => 2087
}

servers.each do |server_name, server_ip|
config.vm.define server_name do |app_config|
app_config.vm.hostname = "#{server_name.to_s}"
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"

# 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: "service network restart", run: "always"

# parallels
app_config.vm.provider :parallels do |p, override|
override.vm.box = "parallels/centos-7.2"
},
'icinga2b' => {
:box => 'centos/7',
:mac => '020027000103',
:net => 'icinga2b.demo.local',
:hostonly => '192.168.33.102',
:memory => '1024',
:cpu => '1',
:fowarded => {
'443' => '8446',
'80' => '8086',
'22' => '2086'
}
},
'icinga2c' => {
:box => 'centos/7',
:mac => '020027000104',
:net => 'icinga2c.demo.local',
:hostonly => '192.168.33.103',
:memory => '1024',
:cpu => '1',
:fowarded => {
'443' => '8447',
'80' => '8087',
'22' => '2087'
}
}
}

p.name = "Icinga 2: #{server_name.to_s}"
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

# Update Parallels Tools automatically
p.update_guest_tools = true
node_config.vm.network :private_network, ip: options[:hostonly] if options[:hostonly]

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

# save storage
p.linked_clone = true
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 = 1024
p.cpus = 1
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"

v.customize ["modifyvm", :id, "--memory", "1024"]
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: 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

# save storage
v.linked_clone = true if Vagrant::VERSION =~ /^1.8/
# 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 = 1024
l.cpus = 1
end
# provisioner: install requirements
node_config.vm.provision :shell, :path => "../scripts/shell_provisioner.sh"

# provisioner
app_config.vm.provision :puppet do |puppet|
# 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"
#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
5 changes: 0 additions & 5 deletions icinga2x-ha-cluster/manifests/finalize.sh

This file was deleted.

26 changes: 0 additions & 26 deletions icinga2x-ha-cluster/manifests/puppet.sh

This file was deleted.

0 comments on commit 768ddd8

Please sign in to comment.