diff --git a/manifests/feature.pp b/manifests/feature.pp index 968caea4d..119dfc846 100644 --- a/manifests/feature.pp +++ b/manifests/feature.pp @@ -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'], diff --git a/manifests/feature/idomysql.pp b/manifests/feature/idomysql.pp index fd0a97085..ab458159f 100644 --- a/manifests/feature/idomysql.pp +++ b/manifests/feature/idomysql.pp @@ -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, @@ -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'], } } @@ -337,6 +344,5 @@ icinga2::feature { 'ido-mysql': ensure => $ensure, - require => Package['icinga2-ido-mysql'] } } diff --git a/manifests/feature/idopgsql.pp b/manifests/feature/idopgsql.pp index ff0d8da0c..b2dc3da7a 100644 --- a/manifests/feature/idopgsql.pp +++ b/manifests/feature/idopgsql.pp @@ -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'.") @@ -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'], } } @@ -159,6 +166,5 @@ icinga2::feature { 'ido-pgsql': ensure => $ensure, - require => Package['icinga2-ido-pgsql'] } } diff --git a/manifests/params.pp b/manifests/params.pp index 3fb3e0e50..b0df41bbe 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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': { @@ -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', @@ -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.") } diff --git a/metadata.json b/metadata.json index 0ced05c19..c8ba7c5c1 100644 --- a/metadata.json +++ b/metadata.json @@ -59,6 +59,13 @@ "operatingsystemrelease": [ "12" ] + }, + { + "operatingsystem": "FreeBSD", + "operatingsystemrelease": [ + "11", + "10" + ] } ] } diff --git a/serverspec/Vagrantfile b/serverspec/Vagrantfile index 3943fe90b..be115e6b3 100644 --- a/serverspec/Vagrantfile +++ b/serverspec/Vagrantfile @@ -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! @@ -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 diff --git a/serverspec/environments/production/manifests/default.pp b/serverspec/environments/production/manifests/default.pp index 507f6c519..6645e4c12 100644 --- a/serverspec/environments/production/manifests/default.pp +++ b/serverspec/environments/production/manifests/default.pp @@ -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': } } diff --git a/serverspec/scripts/i2freebsd10puppet4.sh b/serverspec/scripts/i2freebsd10puppet4.sh new file mode 100644 index 000000000..49ac337f8 --- /dev/null +++ b/serverspec/scripts/i2freebsd10puppet4.sh @@ -0,0 +1,4 @@ +export ASSUME_ALWAYS_YES=YES +pkg bootstrap +pkg update -f +pkg install -y puppet4 diff --git a/serverspec/scripts/i2freebsd11puppet4.sh b/serverspec/scripts/i2freebsd11puppet4.sh new file mode 100644 index 000000000..49ac337f8 --- /dev/null +++ b/serverspec/scripts/i2freebsd11puppet4.sh @@ -0,0 +1,4 @@ +export ASSUME_ALWAYS_YES=YES +pkg bootstrap +pkg update -f +pkg install -y puppet4 diff --git a/serverspec/spec/i2freebsd10puppet4/plattform_independent_spec.rb b/serverspec/spec/i2freebsd10puppet4/plattform_independent_spec.rb new file mode 100644 index 000000000..caa382dc1 --- /dev/null +++ b/serverspec/spec/i2freebsd10puppet4/plattform_independent_spec.rb @@ -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 diff --git a/serverspec/spec/i2freebsd11puppet4/plattform_independent_spec.rb b/serverspec/spec/i2freebsd11puppet4/plattform_independent_spec.rb new file mode 100644 index 000000000..caa382dc1 --- /dev/null +++ b/serverspec/spec/i2freebsd11puppet4/plattform_independent_spec.rb @@ -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 diff --git a/spec/classes/idomysql_spec.rb b/spec/classes/idomysql_spec.rb index a36540c2a..82d6ba53c 100644 --- a/spec/classes/idomysql_spec.rb +++ b/spec/classes/idomysql_spec.rb @@ -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 @@ -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 diff --git a/spec/classes/idopgsql_spec.rb b/spec/classes/idopgsql_spec.rb index f881fe5a1..e6c11411b 100644 --- a/spec/classes/idopgsql_spec.rb +++ b/spec/classes/idopgsql_spec.rb @@ -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 @@ -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 diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index eeb5c71b8..24ad1be32 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,10 +1,6 @@ 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 @@ -12,6 +8,19 @@ 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' }) } @@ -192,4 +201,4 @@ context 'on unsupported plattform' do it { is_expected.to raise_error(Puppet::Error, /bar is not supported/) } end -end \ No newline at end of file +end