Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial FreeBSD support #210

Merged
merged 7 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manifests/feature.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
'present' => link,
default => absent,
},
owner => 'root',
group => 'root',
owner => $user,
group => $group,
target => "../features-available/${feature}.conf",
require => Concat["${conf_dir}/features-available/${feature}.conf"],
notify => Class['::icinga2::service'],
Expand Down
26 changes: 16 additions & 10 deletions manifests/feature/idomysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@
) {

require ::icinga2::config
require ::icinga2::params

$owner = $::icinga2::params::user
$group = $::icinga2::params::group
$node_name = $::icinga2::_constants['NodeName']
$conf_dir = $::icinga2::params::conf_dir
$ssl_dir = "${::icinga2::params::pki_dir}/ido-mysql"
$owner = $::icinga2::params::user
$group = $::icinga2::params::group
$node_name = $::icinga2::_constants['NodeName']
$conf_dir = $::icinga2::params::conf_dir
$ssl_dir = "${::icinga2::params::pki_dir}/ido-mysql"
$ido_mysql_package = $::icinga2::params::ido_mysql_package

File {
owner => $owner,
Expand Down Expand Up @@ -284,17 +286,22 @@
$attrs_ssl = { enable_ssl => $enable_ssl }
}

package { 'icinga2-ido-mysql':
ensure => installed,
if $ido_mysql_package {
package { $ido_mysql_package:
ensure => installed,
before => [
Exec['idomysql-import-schema'],
Icinga2::Feature['ido-mysql']
]
}
}

if $import_schema {
exec { 'idomysql_import_schema':
exec { 'idomysql-import-schema':
user => 'root',
path => $::path,
command => "mysql -h '${host}' -u '${user}' -p'${password}' '${database}' < '/usr/share/icinga2-ido-mysql/schema/mysql.sql'",
unless => "mysql -h '${host}' -u '${user}' -p'${password}' '${database}' -Ns -e 'select version from icinga_dbversion'",
require => Package['icinga2-ido-mysql'],
}
}

Expand Down Expand Up @@ -337,6 +344,5 @@

icinga2::feature { 'ido-mysql':
ensure => $ensure,
require => Package['icinga2-ido-mysql']
}
}
18 changes: 12 additions & 6 deletions manifests/feature/idopgsql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@
) {

require ::icinga2::config
require ::icinga2::params

$conf_dir = $::icinga2::params::conf_dir
$conf_dir = $::icinga2::params::conf_dir
$ido_pgsql_package = $::icinga2::params::ido_pgsql_package

validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
Expand All @@ -107,18 +109,23 @@
if $categories { validate_array($categories) }
validate_bool($import_schema)

package { 'icinga2-ido-pgsql':
ensure => installed,
if $ido_pgsql_package {
package { $ido_pgsql_package:
ensure => installed,
before => [
Exec['idopgsql-import-schema'],
Icinga2::Feature['ido-pgsql'],
]
}
}

if $import_schema {
exec { 'idopgsql_import_schema':
exec { 'idopgsql-import-schema':
user => 'root',
path => $::path,
environment => ["PGPASSWORD=${password}"],
command => "psql -h '${host}' -U '${user}' -d '${database}' -w -f /usr/share/icinga2-ido-pgsql/schema/pgsql.sql",
unless => "psql -h '${host}' -U '${user}' -d '${database}' -w -c 'select version from icinga_dbversion'",
require => Package['icinga2-ido-pgsql'],
}
}

Expand Down Expand Up @@ -159,6 +166,5 @@

icinga2::feature { 'ido-pgsql':
ensure => $ensure,
require => Package['icinga2-ido-pgsql']
}
}
61 changes: 45 additions & 16 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@
case $::kernel {

'linux': {
$conf_dir = '/etc/icinga2'
$log_dir = '/var/log/icinga2'
$run_dir = '/var/run/icinga2'
$spool_dir = '/var/spool/icinga2'
$cache_dir = '/var/cache/icinga2'
$pki_dir = "${conf_dir}/pki"
$ca_dir = '/var/lib/icinga2/ca'
$conf_dir = '/etc/icinga2'
$log_dir = '/var/log/icinga2'
$run_dir = '/var/run/icinga2'
$spool_dir = '/var/spool/icinga2'
$cache_dir = '/var/cache/icinga2'
$pki_dir = "${conf_dir}/pki"
$ca_dir = '/var/lib/icinga2/ca'
$ido_pgsql_package = 'icinga2-ido-pgsql'
$ido_mysql_package = 'icinga2-ido-mysql'

case $::osfamily {
'redhat': {
Expand Down Expand Up @@ -133,15 +135,18 @@
} # Linux

'windows': {
$user = 'SYSTEM'
$group = undef
$conf_dir = 'C:/ProgramData/icinga2/etc/icinga2'
$log_dir = 'C:/ProgramData/icinga2/var/log/icinga2'
$run_dir = 'C:/ProgramData/icinga2/var/run/icinga2'
$spool_dir = 'C:/ProgramData/icinga2/var/spool/icinga2'
$cache_dir = 'C:/ProgramData/icinga2/var/cache/icinga2'
$pki_dir = "${conf_dir}/pki"
$ca_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/ca'
$user = 'SYSTEM'
$group = undef
$conf_dir = 'C:/ProgramData/icinga2/etc/icinga2'
$log_dir = 'C:/ProgramData/icinga2/var/log/icinga2'
$run_dir = 'C:/ProgramData/icinga2/var/run/icinga2'
$spool_dir = 'C:/ProgramData/icinga2/var/spool/icinga2'
$cache_dir = 'C:/ProgramData/icinga2/var/cache/icinga2'
$pki_dir = "${conf_dir}/pki"
$ca_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/ca'
$ido_pgsql_package = undef
$ido_mysql_package = undef

$constants = {
'PluginDir' => 'C:/Program Files/ICINGA2/sbin',
'PluginContribDir' => 'C:/Program Files/ICINGA2/sbin',
Expand All @@ -152,6 +157,30 @@
}
} # Windows

'FreeBSD': {
$conf_dir = '/usr/local/etc/icinga2'
$log_dir = '/var/log/icinga2'
$run_dir = '/var/run/icinga2'
$spool_dir = '/var/spool/icinga2'
$cache_dir = '/var/cache/icinga2'
$pki_dir = "${conf_dir}/pki"
$ca_dir = '/var/icinga2/ca'
$user = 'icinga'
$group = 'icinga'
$lib_dir = '/usr/local/lib/icinga2'
$ido_pgsql_package = undef
$ido_mysql_package = undef

$constants = {
'PluginDir' => '/usr/local/libexec/nagios',
'PluginContribDir' => '/usr/local/share/icinga2/include/plugins-contrib.d',
'ManubulonPluginDir' => '/usr/local/libexec/nagios',
'ZoneName' => $::fqdn,
'NodeName' => $::fqdn,
'TicketSalt' => '',
}
} # FreeBSD

default: {
fail("Your plattform ${::osfamily} is not supported, yet.")
}
Expand Down
7 changes: 7 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
"operatingsystemrelease": [
"12"
]
},
{
"operatingsystem": "FreeBSD",
"operatingsystemrelease": [
"11",
"10"
]
}
]
}
16 changes: 16 additions & 0 deletions serverspec/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ nodes = {
:url => 'http://boxes.icinga.com/vagrant/private/w2k12r2.box',
:md5 => '8d2f63885253289bfcad47256146ea02'
},
'i2freebsd10puppet4' => {
:box => 'freebsd-10.3-amd64-virtualbox',
:url => 'http://boxes.icinga.com/vagrant/freebsd/freebsd-10.3-amd64-virtualbox.box',
:md5 => '68c708200667c6fd075d24a3f8e29061',
:kernel => 'bsd'
},
'i2freebsd11puppet4' => {
:box => 'freebsd-10.3-amd64-virtualbox',
:url => 'http://boxes.icinga.com/vagrant/freebsd/freebsd-11.0-amd64-virtualbox.box',
:md5 => '3ee3583815214a7443e9a0d288241cc4',
:kernel => 'bsd'
},
}

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
Expand All @@ -58,6 +70,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
node_config.vm.box_download_checksum_type = 'md5'
node_config.vm.network :private_network, :adapter => 2, ip: options[:ip] if options[:ip]

if options[:kernel] == "bsd"
node_config.vm.synced_folder "./environments", "/tmp/vagrant-puppet/environments", type: "rsync"
end

if options[:forwarded]
options[:forwarded].each_pair do |guest, local|
node_config.vm.network "forwarded_port", guest: guest, host: local
Expand Down
20 changes: 17 additions & 3 deletions serverspec/environments/production/manifests/default.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
node default {
class { 'icinga2':
manage_repo => true,
node /(debian|rhel|ubuntu|sles)/ {
class { '::icinga2':
constants => {
'TicketSalt' => '5a3d695b8aef8f18452fc494593056a4',
}
}

class{ '::icinga2::feature::idomysql':
user => 'icinga2',
password => 'icinga2',
database => 'icinga2',
import_schema => true,
}

}

node /freebsd/ {
class { 'icinga2': }
}
4 changes: 4 additions & 0 deletions serverspec/scripts/i2freebsd10puppet4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export ASSUME_ALWAYS_YES=YES
pkg bootstrap
pkg update -f
pkg install -y puppet4
4 changes: 4 additions & 0 deletions serverspec/scripts/i2freebsd11puppet4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export ASSUME_ALWAYS_YES=YES
pkg bootstrap
pkg update -f
pkg install -y puppet4
10 changes: 10 additions & 0 deletions serverspec/spec/i2freebsd10puppet4/plattform_independent_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'

describe package('icinga2') do
it { should be_installed }
end

describe service('icinga2') do
it { should be_enabled }
it { should be_running }
end
10 changes: 10 additions & 0 deletions serverspec/spec/i2freebsd11puppet4/plattform_independent_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'

describe package('icinga2') do
it { should be_installed }
end

describe service('icinga2') do
it { should be_enabled }
it { should be_running }
end
8 changes: 4 additions & 4 deletions spec/classes/idomysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@
context "#{os} with import_schema => true" do
let(:params) { {:import_schema => true} }

it { is_expected.to contain_exec('idomysql_import_schema') }
it { is_expected.to contain_exec('idomysql-import-schema') }
end


context "#{os} with import_schema => false" do
let(:params) { {:import_schema => false} }

it { should_not contain_exec('idomysql_import_schema') }
it { should_not contain_exec('idomysql-import-schema') }
end


Expand Down Expand Up @@ -655,14 +655,14 @@
context "Windows 2012 R2 with import_schema => true" do
let(:params) { {:import_schema => true} }

it { is_expected.to contain_exec('idomysql_import_schema') }
it { is_expected.to contain_exec('idomysql-import-schema') }
end


context "Windows 2012 R2 with import_schema => false" do
let(:params) { {:import_schema => false} }

it { should_not contain_exec('idomysql_import_schema') }
it { should_not contain_exec('idomysql-import-schema') }
end


Expand Down
8 changes: 4 additions & 4 deletions spec/classes/idopgsql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@
context "#{os} with import_schema => true" do
let(:params) { {:import_schema => true} }

it { is_expected.to contain_exec('idopgsql_import_schema') }
it { is_expected.to contain_exec('idopgsql-import-schema') }
end


context "#{os} with import_schema => false" do
let(:params) { {:import_schema => false} }

it { should_not contain_exec('idopgsql_import_schema') }
it { should_not contain_exec('idopgsql-import-schema') }
end


Expand Down Expand Up @@ -379,14 +379,14 @@
context "Windows 2012 R2 with import_schema => true" do
let(:params) { {:import_schema => true} }

it { is_expected.to contain_exec('idopgsql_import_schema') }
it { is_expected.to contain_exec('idopgsql-import-schema') }
end


context "Windows 2012 R2 with import_schema => false" do
let(:params) { {:import_schema => false} }

it { should_not contain_exec('idopgsql_import_schema') }
it { should_not contain_exec('idopgsql-import-schema') }
end


Expand Down
19 changes: 14 additions & 5 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
require 'spec_helper'

describe('icinga2', :type => :class) do
before(:all) do
@icinga2_conf = '/etc/icinga2/icinga2.conf'
@constants_conf = '/etc/icinga2/constants.conf'
end

on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end

case facts[:kernel]
when 'Linux'
before(:all) do
@icinga2_conf = '/etc/icinga2/icinga2.conf'
@constants_conf = '/etc/icinga2/constants.conf'
end
when 'FreeBSD'
before(:all) do
@icinga2_conf = '/usr/local/etc/icinga2/icinga2.conf'
@constants_conf = '/usr/local/etc/icinga2/constants.conf'
end
end

context 'with all default parameters' do
it { is_expected.to contain_package('icinga2').with({ 'ensure' => 'installed' }) }

Expand Down Expand Up @@ -192,4 +201,4 @@
context 'on unsupported plattform' do
it { is_expected.to raise_error(Puppet::Error, /bar is not supported/) }
end
end
end