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

Convert params.pp to hiera data #269

Merged
merged 5 commits into from Jan 9, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions data/common.yaml
@@ -0,0 +1,6 @@
---
postfix::params::aliasesseltype: ~
postfix::params::seltype: ~
postfix::params::mailx_package: 'mailx'
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
...
2 changes: 2 additions & 0 deletions data/os/Alpine.yaml
@@ -0,0 +1,2 @@
---
postfix::params::master_os_template: "postfix/master.cf.debian.erb"
4 changes: 4 additions & 0 deletions data/osfamily/Debian.yaml
@@ -0,0 +1,4 @@
---
postfix::params::mailx_package: 'bsd-mailx'
postfix::params::master_os_template: 'postfix/master.cf.debian.erb'
...
3 changes: 3 additions & 0 deletions data/osfamily/Debian/etch.yaml
@@ -0,0 +1,3 @@
---
postfix::params::mailx_package: 'mailx'
...
3 changes: 3 additions & 0 deletions data/osfamily/Debian/lenny.yaml
@@ -0,0 +1,3 @@
---
postfix::params::mailx_package: 'mailx'
...
3 changes: 3 additions & 0 deletions data/osfamily/Debian/sarge.yaml
@@ -0,0 +1,3 @@
---
postfix::params::mailx_package: 'mailx'
...
6 changes: 6 additions & 0 deletions data/osfamily/RedHat.yaml
@@ -0,0 +1,6 @@
---
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'
...
5 changes: 5 additions & 0 deletions data/osfamily/RedHat/4.yaml
@@ -0,0 +1,5 @@
---
postfix::params::aliasesseltype: 'etc_t'
postfix::params::seltype: 'etc_t'
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
...
4 changes: 4 additions & 0 deletions data/osfamily/RedHat/5.yaml
@@ -0,0 +1,4 @@
---
postfix::params::aliasesseltype: 'postfix_etc_t'
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
...
3 changes: 3 additions & 0 deletions data/osfamily/RedHat/6.yaml
@@ -0,0 +1,3 @@
---
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
...
4 changes: 4 additions & 0 deletions data/osfamily/Suse.yaml
@@ -0,0 +1,4 @@
---
postfix::params::restart_cmd: '/usr/bin/systemctl reload postfix'
postfix::params::master_os_template: "postfix/master.cf.sles.erb"
...
4 changes: 4 additions & 0 deletions data/osfamily/Suse/11.yaml
@@ -0,0 +1,4 @@
---
postfix::params::restart_cmd: '/etc/init.d/postfix reload'
postfix::params::master_os_template: "postfix/master.cf.SLES%{::operatingsystemrelease}.erb"
...
19 changes: 19 additions & 0 deletions hiera.yaml
@@ -0,0 +1,19 @@
---
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"
...
97 changes: 24 additions & 73 deletions manifests/params.pp
@@ -1,74 +1,25 @@
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,
) {
}
8 changes: 8 additions & 0 deletions metadata.json
Expand Up @@ -56,6 +56,14 @@
},
{
"operatingsystem": "Alpine"
},
{
"operatingsystem": "Fedora",
"operatingsystemrelease": [
"28",
"29",
"30"
]
}
]
}
27 changes: 19 additions & 8 deletions spec/classes/postfix_spec.rb
Expand Up @@ -73,14 +73,25 @@
: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
Expand Down