Skip to content

Commit

Permalink
Merge pull request #672 from cocker-cc/Use_Facts-Hash
Browse files Browse the repository at this point in the history
Use new hash style for facts
  • Loading branch information
lbetz authored Aug 18, 2021
2 parents e24f1be + 5e418f6 commit be3c7c8
Show file tree
Hide file tree
Showing 30 changed files with 84 additions and 79 deletions.
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$confd = $::icinga2::_confd
$purge_features = $::icinga2::purge_features

if $::kernel != 'windows' {
if $::facts['kernel'] != 'windows' {
$template_constants = icinga2_attributes($constants)
$template_mainconfig = template('icinga2/icinga2.conf.erb')
$file_permissions = '0640'
Expand Down
2 changes: 1 addition & 1 deletion manifests/config/fragment.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
Variant[String, Integer] $order = '00',
) {

case $::osfamily {
case $::facts['os']['family'] {
'windows': {
$_content = regsubst($content, '\n', "\r\n", 'EMG')
} # windows
Expand Down
2 changes: 1 addition & 1 deletion manifests/feature.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$group = $::icinga2::globals::group
$conf_dir = $::icinga2::globals::conf_dir

if $::osfamily != 'windows' {
if $::facts['os']['family'] != 'windows' {
$_ensure = $ensure ? {
'present' => link,
default => absent,
Expand Down
22 changes: 11 additions & 11 deletions manifests/feature/api.pp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
# Fingerprint of the CA host certificate for validation. Requires pki is set to `icinga2`.
# You can get the fingerprint via 'openssl x509 -noout -fingerprint -sha256 -inform pem -in [certificate-file.crt]'
# on your CA host. (Icinga2 versions before 2.12.0 require '-sha1' as digest algorithm.)
#
#
# @param [String] ticket_salt
# Salt to use for ticket generation. The salt is stored to api.conf if none or ca is chosen for pki.
# Defaults to constant TicketSalt. Keep in mind this parameter is parsed so please use only alpha numric
Expand Down Expand Up @@ -187,7 +187,7 @@
$user = $::icinga2::globals::user
$group = $::icinga2::globals::group
$node_name = $::icinga2::_constants['NodeName']
$_ssl_key_mode = $::osfamily ? {
$_ssl_key_mode = $::facts['os']['family'] ? {
'windows' => undef,
default => '0600',
}
Expand Down Expand Up @@ -215,21 +215,21 @@
file { $_ssl_key_path:
ensure => file,
mode => $_ssl_key_mode,
source => $::icinga2_puppet_hostprivkey,
source => $::facts['icinga2_puppet_hostprivkey'],
tag => 'icinga2::config::file',
show_diff => false,
backup => false,
}

file { $_ssl_cert_path:
ensure => file,
source => $::icinga2_puppet_hostcert,
source => $::facts['icinga2_puppet_hostcert'],
tag => 'icinga2::config::file',
}

file { $_ssl_cacert_path:
ensure => file,
source => $::icinga2_puppet_localcacert,
source => $::facts['icinga2_puppet_localcacert'],
tag => 'icinga2::config::file',
}
} # puppet
Expand All @@ -240,7 +240,7 @@
$_ticket_salt = $ticket_salt

if $ssl_key {
$_ssl_key = $::osfamily ? {
$_ssl_key = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_key, '\n', "\r\n", 'EMG'),
default => $ssl_key,
}
Expand All @@ -256,7 +256,7 @@
}

if $ssl_cert {
$_ssl_cert = $::osfamily ? {
$_ssl_cert = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_cert, '\n', "\r\n", 'EMG'),
default => $ssl_cert,
}
Expand All @@ -269,7 +269,7 @@
}

if $ssl_cacert {
$_ssl_cacert = $::osfamily ? {
$_ssl_cacert = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_cacert, '\n', "\r\n", 'EMG'),
default => $ssl_cacert,
}
Expand Down Expand Up @@ -298,7 +298,7 @@
}
if $fingerprint {
$_fingerprint = upcase(regsubst($fingerprint, ':', ' ', 'G'))
if $::osfamily != 'Windows' {
if $::facts['os']['family'] != 'Windows' {
$_cmd_pki_get_cert = "${cmd_pki_get_cert} |grep '${_fingerprint}\s*$'"
} else {
$_cmd_pki_get_cert = "cmd.exe /c \"${cmd_pki_get_cert} |findstr /R /C:\"${_fingerprint}\"\""
Expand All @@ -307,7 +307,7 @@
$_cmd_pki_get_cert = $cmd_pki_get_cert
}

$_env = $::kernel ? {
$_env = $::facts['kernel'] ? {
'windows' => undef,
default => ["ICINGA2_USER=${user}", "ICINGA2_GROUP=${group}"],
}
Expand All @@ -323,7 +323,7 @@
}

-> exec { 'icinga2 pki get trusted-cert':
path => $::path,
path => $::facts['path'],
command => $_cmd_pki_get_cert,
creates => $trusted_cert,
}
Expand Down
8 changes: 4 additions & 4 deletions manifests/feature/elasticsearch.pp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
if $enable_ssl {

$ssl_dir = $::icinga2::globals::cert_dir
$_ssl_key_mode = $::kernel ? {
$_ssl_key_mode = $::facts['kernel'] ? {
'windows' => undef,
default => '0600',
}
Expand All @@ -111,7 +111,7 @@
$_ssl_key_path = "${ssl_dir}/ElasticsearchWriter_elasticsearch.key"
}

$_ssl_key = $::osfamily ? {
$_ssl_key = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_key, '\n', "\r\n", 'EMG'),
default => $ssl_key,
}
Expand All @@ -133,7 +133,7 @@
$_ssl_cert_path = "${ssl_dir}/ElasticsearchWriter_elasticsearch.crt"
}

$_ssl_cert = $::osfamily ? {
$_ssl_cert = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_cert, '\n', "\r\n", 'EMG'),
default => $ssl_cert,
}
Expand All @@ -154,7 +154,7 @@
$_ssl_cacert_path = "${ssl_dir}/ElasticsearchWriter_elasticsearch_ca.crt"
}

$_ssl_cacert = $::osfamily ? {
$_ssl_cacert = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_cacert, '\n', "\r\n", 'EMG'),
default => $ssl_cacert,
}
Expand Down
12 changes: 6 additions & 6 deletions manifests/feature/idomysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
$manage_package = $::icinga2::manage_package
$manage_packages = $::icinga2::manage_packages

$_ssl_key_mode = $::osfamily ? {
$_ssl_key_mode = $::facts['os']['family'] ? {
'windows' => undef,
default => '0600',
}
Expand Down Expand Up @@ -171,7 +171,7 @@
$_ssl_key_path = "${ssl_dir}/IdoMysqlConnection_ido-mysql.key"
}

$_ssl_key = $::osfamily ? {
$_ssl_key = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_key, '\n', "\r\n", 'EMG'),
default => $ssl_key,
}
Expand All @@ -193,7 +193,7 @@
$_ssl_cert_path = "${ssl_dir}/IdoMysqlConnection_ido-mysql.crt"
}

$_ssl_cert = $::osfamily ? {
$_ssl_cert = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_cert, '\n', "\r\n", 'EMG'),
default => $ssl_cert,
}
Expand All @@ -214,7 +214,7 @@
$_ssl_cacert_path = "${ssl_dir}/IdoMysqlConnection_ido-mysql_ca.crt"
}

$_ssl_cacert = $::osfamily ? {
$_ssl_cacert = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_cacert, '\n', "\r\n", 'EMG'),
default => $ssl_cacert,
}
Expand Down Expand Up @@ -276,7 +276,7 @@

# install additional package
if $ido_mysql_package_name and ($manage_package or $manage_packages) {
if $::osfamily == 'debian' {
if $::facts['os']['family'] == 'debian' {
ensure_resources('file', { '/etc/dbconfig-common' => { ensure => directory, owner => 'root', group => 'root' } })
file { "/etc/dbconfig-common/${ido_mysql_package_name}.conf":
ensure => file,
Expand All @@ -301,7 +301,7 @@
}
exec { 'idomysql-import-schema':
user => 'root',
path => $::path,
path => $::facts['path'],
command => "${_mysql_command} < \"${ido_mysql_schema}\"",
unless => "${_mysql_command} -Ns -e 'select version from icinga_dbversion'",
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/feature/idopgsql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

# install additional package
if $ido_pgsql_package_name and ($manage_package or $manage_packages) {
if $::osfamily == 'debian' {
if $::facts['os']['family'] == 'debian' {
ensure_resources('file', { '/etc/dbconfig-common' => { ensure => directory, owner => 'root', group => 'root' } })
file { "/etc/dbconfig-common/${ido_pgsql_package_name}.conf":
ensure => file,
Expand All @@ -133,7 +133,7 @@
}
exec { 'idopgsql-import-schema':
user => 'root',
path => $::path,
path => $::facts['path'],
environment => ["PGPASSWORD=${password}"],
command => "psql -h '${host}' -U '${user}' -p '${port}' -d '${database}' -w -f \"${ido_pgsql_schema}\"",
unless => "psql -h '${host}' -U '${user}' -p '${port}' -d '${database}' -w -c 'select version from icinga_dbversion'",
Expand Down
8 changes: 4 additions & 4 deletions manifests/feature/influxdb.pp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
$group = $::icinga2::globals::group
$conf_dir = $::icinga2::globals::conf_dir
$ssl_dir = $::icinga2::globals::cert_dir
$_ssl_key_mode = $::kernel ? {
$_ssl_key_mode = $::facts['kernel'] ? {
'windows' => undef,
default => '0600',
}
Expand All @@ -135,7 +135,7 @@
$_ssl_key_path = "${ssl_dir}/InfluxdbWriter_influxdb.key"
}

$_ssl_key = $::osfamily ? {
$_ssl_key = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_key, '\n', "\r\n", 'EMG'),
default => $ssl_key,
}
Expand All @@ -157,7 +157,7 @@
$_ssl_cert_path = "${ssl_dir}/InfluxdbWriter_influxdb.crt"
}

$_ssl_cert = $::osfamily ? {
$_ssl_cert = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_cert, '\n', "\r\n", 'EMG'),
default => $ssl_cert,
}
Expand All @@ -178,7 +178,7 @@
$_ssl_cacert_path = "${ssl_dir}/InfluxdbWriter_influxdb_ca.crt"
}

$_ssl_cacert = $::osfamily ? {
$_ssl_cacert = $::facts['os']['family'] ? {
'windows' => regsubst($ssl_cacert, '\n', "\r\n", 'EMG'),
default => $ssl_cacert,
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/globals.pp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@

assert_private()

if ( versioncmp($::puppetversion, '6' ) >= 0 and versioncmp(load_module_metadata('stdlib')['version'], '5.1.0') < 0 ) {
if ( versioncmp($::facts['puppetversion'], '6' ) >= 0 and versioncmp(load_module_metadata('stdlib')['version'], '5.1.0') < 0 ) {
fail('You be affected by this bug: https://github.com/Icinga/puppet-icinga2/issues/505 so you should update your stdlib to version 5.1 or higher')
}

# Logon account on Windows
if $facts['os']['kernel'] == 'windows' {
if $logon_account and versioncmp($::puppetversion, '6.18.0') < 0 {
if $logon_account and versioncmp($::facts['puppetversion'], '6.18.0') < 0 {
fail('Using logon_account requieres a Puppet version 6.18 or higher')
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$group = $::icinga2::globals::group

if $manage_package or $manage_packages {
if $::osfamily == 'windows' { Package { provider => chocolatey, } }
if $::facts['os']['family'] == 'windows' { Package { provider => chocolatey, } }

package { $package_name:
ensure => installed,
Expand Down
4 changes: 2 additions & 2 deletions manifests/object.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

assert_private()

case $::osfamily {
case $::facts['os']['family'] {
'windows': {
} # windows
default: {
Expand All @@ -89,7 +89,7 @@
'ignore where' => $ignore,
})

$_content = $::osfamily ? {
$_content = $::facts['os']['family'] ? {
'windows' => regsubst(template('icinga2/object.conf.erb'), '\n', "\r\n", 'EMG'),
default => template('icinga2/object.conf.erb'),
}
Expand Down
6 changes: 3 additions & 3 deletions manifests/pki/ca.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
group => $group,
}

if $::osfamily != 'windows' {
if $::facts['os']['family'] != 'windows' {
$_ca_key_mode = '0600'
} else {
$_ca_key_mode = undef
Expand All @@ -60,7 +60,7 @@
notify => Class['::icinga2::service'],
}
} else {
if $::osfamily == 'windows' {
if $::facts['os']['family'] == 'windows' {
$_ca_cert = regsubst($ca_cert, '\n', "\r\n", 'EMG')
$_ca_key = regsubst($ca_key, '\n', "\r\n", 'EMG')
} else {
Expand Down Expand Up @@ -91,7 +91,7 @@

file { $_ssl_cacert_path:
ensure => file,
source => $::kernel ? {
source => $::facts['kernel'] ? {
'windows' => "file:///${ca_dir}/ca.crt",
default => "${ca_dir}/ca.crt",
},
Expand Down
2 changes: 1 addition & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}

if $manage_service {
if $facts['os']['kernel'] == 'windows' and versioncmp($::puppetversion, '6.18.0') >= 0 {
if $facts['os']['kernel'] == 'windows' and versioncmp($::facts['puppetversion'], '6.18.0') >= 0 {
service { $service_name:
ensure => $ensure,
enable => $enable,
Expand Down
6 changes: 3 additions & 3 deletions spec/classes/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@
@icinga2_conf_dir = '/etc/icinga2'
@icinga2_pki_dir = '/var/lib/icinga2/certs'
@icinga2_sslkey_mode = '0600'
case facts[:osfamily]
case facts[:os]['family']
when 'Debian'
@icinga2_user = 'nagios'
@icinga2_group = 'nagios'
@icinga2_bin = '/usr/sbin/icinga2'
else
@icinga2_user = 'icinga'
@icinga2_group = 'icinga'
if facts[:osfamily] != 'RedHat'
if facts[:os]['family'] != 'RedHat'
@icinga2_bin = '/usr/sbin/icinga2'
else
case facts[:operatingsystemmajrelease]
case facts[:os]['release']['major']
when '5'
@icinga2_bin = '/usr/sbin/icinga2'
when '6'
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/debuglog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
.with({ 'target' => "#{@icinga2_conf_dir}/features-available/debuglog.conf" })
.that_notifies('Class[icinga2::service]') }

case facts[:osfamily]
case facts[:os]['family']
when 'windows'
it { is_expected.to contain_concat__fragment('icinga2::object::FileLogger::debuglog')
.with({
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/elasticsearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@icinga2_user = 'icinga'
@icinga2_group = 'icinga'
else
case facts[:osfamily]
case facts[:os]['family']
when 'Debian'
@icinga2_conf_dir = '/etc/icinga2'
@icinga2_pki_dir = '/var/lib/icinga2/certs'
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/gelf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
it { is_expected.to contain_icinga2__feature('gelf').with({'ensure' => 'absent'}) }
end
end

end
end
Loading

0 comments on commit be3c7c8

Please sign in to comment.