Unverified Commit 33604bd1 authored by Raphaël Pinson's avatar Raphaël Pinson Committed by GitHub

Convert params.pp to hiera data (#269)

* Added hieradata definition. Migrated most params.pp logic to hieradata.
Added Fedora to spec tests.

* Corrected reversal of hiera.yaml names

* Removed Archlinux items as they were intended for a subsequent update.

* Move all params.pp logic to hiera

* Simplify params.pp with hiera data
Co-authored-by: default avatarQuien Sabe <qs5779@mail.com>
parent 9fbae3ce
---
postfix::params::aliasesseltype: ~
postfix::params::seltype: ~
postfix::params::mailx_package: 'mailx'
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
...
---
postfix::params::master_os_template: "postfix/master.cf.debian.erb"
---
postfix::params::mailx_package: 'bsd-mailx'
postfix::params::master_os_template: 'postfix/master.cf.debian.erb'
...
---
postfix::params::mailx_package: 'mailx'
...
---
postfix::params::mailx_package: 'mailx'
...
---
postfix::params::mailx_package: 'mailx'
...
---
postfix::params::aliasesseltype: 'etc_aliases_t'
postfix::params::seltype: 'postfix_etc_t'
postfix::params::restart_cmd: '/bin/systemctl reload postfix'
postfix::params::master_os_template: 'postfix/master.cf.redhat.erb'
...
---
postfix::params::aliasesseltype: 'etc_t'
postfix::params::seltype: 'etc_t'
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
...
---
postfix::params::aliasesseltype: 'postfix_etc_t'
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
...
---
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
...
---
postfix::params::restart_cmd: '/usr/bin/systemctl reload postfix'
postfix::params::master_os_template: "postfix/master.cf.sles.erb"
...
---
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
postfix::params::master_os_template: "postfix/master.cf.SLES%{::operatingsystemrelease}.erb"
...
---
version: 5
defaults: # Used for any hierarchy level that omits these keys.
datadir: data # This path is relative to hiera.yaml's directory.
data_hash: yaml_data # Use the built-in YAML backend.
hierarchy:
- name: "Per-OS name" # example Alpine, Fedora
path: "os/%{facts.os.name}.yaml"
- name: "Per-OS family"
paths:
- "osfamily/%{facts.os.family}/%{facts.lsbdistcodename}.yaml"
- "osfamily/%{facts.os.family}/%{facts.operatingsystemmajrelease}.yaml"
- "osfamily/%{facts.os.family}.yaml"
- name: "Common data"
path: "common.yaml"
...
class postfix::params {
case $::osfamily {
'RedHat': {
$aliasesseltype = $::operatingsystemmajrelease ? {
'4' => 'etc_t',
/5/ => 'postfix_etc_t',
/6|7|8/ => 'etc_aliases_t',
default => undef,
}
$seltype = $::operatingsystemmajrelease ? {
'4' => 'etc_t',
/5|6|7|8/ => 'postfix_etc_t',
default => undef,
}
$restart_cmd = $::operatingsystemmajrelease ? {
/7|8/ => '/bin/systemctl reload postfix',
default => '/etc/init.d/postfix reload',
}
$mailx_package = 'mailx'
$master_os_template = "${module_name}/master.cf.redhat.erb"
}
'Debian': {
$aliasesseltype = undef
$seltype = undef
$restart_cmd = '/etc/init.d/postfix reload'
$mailx_package = $::lsbdistcodename ? {
/^(sarge|etch|lenny)$/ => 'mailx',
default => 'bsd-mailx',
}
$master_os_template = "${module_name}/master.cf.debian.erb"
}
'Suse': {
$aliasesseltype = undef
$seltype = undef
$mailx_package = 'mailx'
if $::operatingsystemmajrelease == '11' {
$restart_cmd = '/etc/init.d/postfix reload'
$master_os_template = "${module_name}/master.cf.${::operatingsystem}${::operatingsystemrelease}.erb"
} else {
$restart_cmd = '/usr/bin/systemctl reload postfix'
$master_os_template = "${module_name}/master.cf.sles.erb"
}
}
default: {
case $::operatingsystem {
'Alpine': {
$aliasesseltype = undef
$seltype = undef
$restart_cmd = '/etc/init.d/postfix reload'
$mailx_package = 'mailx'
$master_os_template = "${module_name}/master.cf.debian.erb"
}
default: {
fail "Unsupported OS family '${::osfamily}' and OS '${::operatingsystem}'"
}
}
}
}
#
# == Class: postfix::params
#
# This class provides the appropriate values for operating system specific variables.
#
# === Parameters
#
# [*mailx_package*] - (string) Name of package that provides mailx
#
# [*restart_cmd*] - (hash) Command to use when restarting postfix
#
# [*aliasesseltype*] - (string) Selinux type for /etc/aliases
#
# [*seltype*] - (string) Selinux type for /etc/postfix/* config files
#
# [*master_os_template*] - (string) Path to the master template
#
class postfix::params (
String $mailx_package,
String $restart_cmd,
String $master_os_template,
Optional[String] $aliasesseltype,
Optional[String] $seltype,
) {
}
......@@ -56,6 +56,14 @@
},
{
"operatingsystem": "Alpine"
},
{
"operatingsystem": "Fedora",
"operatingsystemrelease": [
"28",
"29",
"30"
]
}
]
}
......@@ -73,14 +73,25 @@ describe 'postfix' do
:restart => '/etc/init.d/postfix reload'
) }
else
it { is_expected.to contain_file('/etc/aliases').with_seltype('postfix_etc_t').with_content("# file managed by puppet\n") }
it {
is_expected.to contain_service('postfix').with(
:ensure => 'running',
:enable => 'true',
:hasstatus => 'true',
:restart => '/etc/init.d/postfix reload'
) }
if facts[:operatingsystem] == 'Fedora'
it { is_expected.to contain_file('/etc/aliases').with_seltype('etc_aliases_t').with_content("# file managed by puppet\n") }
it {
is_expected.to contain_service('postfix').with(
:ensure => 'running',
:enable => 'true',
:hasstatus => 'true',
:restart => '/bin/systemctl reload postfix'
) }
else
it { is_expected.to contain_file('/etc/aliases').with_seltype('postfix_etc_t').with_content("# file managed by puppet\n") }
it {
is_expected.to contain_service('postfix').with(
:ensure => 'running',
:enable => 'true',
:hasstatus => 'true',
:restart => '/etc/init.d/postfix reload'
) }
end
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment