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

Move resources to related classes #42

Merged
merged 3 commits into from Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
47 changes: 0 additions & 47 deletions manifests/config.pp
Expand Up @@ -5,20 +5,6 @@

class caddy::config inherits caddy {

group {$caddy::caddy_group:
ensure => present,
system => true,
}

user {$caddy::caddy_user:
ensure => present,
shell => '/sbin/nologin',
gid => $caddy::caddy_group,
system => true,
home => $caddy::caddy_home,
managehome => true,
}

file {$caddy::caddy_ssl_dir:
ensure => directory,
owner => $caddy::caddy_user,
Expand Down Expand Up @@ -60,37 +46,4 @@
group => $caddy::caddy_group,
require => User[$caddy::caddy_user],
}

case $facts['os']['release']['major'] {
'7': {
file {'/etc/systemd/system/caddy.service':
ensure => file,
mode => '0744',
owner => 'root',
group => 'root',
content => template('caddy/etc/systemd/system/caddy.service.erb'),
notify => Exec['systemctl-daemon-reload'],
require => Class['caddy::package'],
}

exec {'systemctl-daemon-reload':
refreshonly => true,
path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin',
command => 'systemctl daemon-reload',
}
}
'6': {
file {'/etc/init.d/caddy':
ensure => file,
mode => '0744',
owner => 'root',
group => 'root',
content => template('caddy/etc/init.d/caddy.erb'),
require => Class['caddy::package'],
}
}
default: {
fail("${facts['os']['family']} is not supported.")
}
}
}
14 changes: 14 additions & 0 deletions manifests/init.pp
Expand Up @@ -47,6 +47,20 @@

)inherits caddy::params{

group { $caddy::caddy_group:
ensure => present,
system => true,
}

user { $caddy::caddy_user:
ensure => present,
shell => '/sbin/nologin',
gid => $caddy::caddy_group,
system => true,
home => $caddy::caddy_home,
managehome => true,
}

include caddy::package
include caddy::config
include caddy::service
Expand Down
33 changes: 33 additions & 0 deletions manifests/service.pp
Expand Up @@ -5,6 +5,39 @@
#
class caddy::service inherits caddy {

case $facts['os']['release']['major'] {
'7': {
file {'/etc/systemd/system/caddy.service':
ensure => file,
mode => '0744',
owner => 'root',
group => 'root',
content => template('caddy/etc/systemd/system/caddy.service.erb'),
notify => Exec['systemctl-daemon-reload'],
require => Class['caddy::package'],
}

exec {'systemctl-daemon-reload':
refreshonly => true,
path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin',
command => 'systemctl daemon-reload',
}
}
'6': {
file {'/etc/init.d/caddy':
ensure => file,
mode => '0744',
owner => 'root',
group => 'root',
content => template('caddy/etc/init.d/caddy.erb'),
require => Class['caddy::package'],
}
}
default: {
fail("${facts['os']['family']} is not supported.")
}
}

service{'caddy':
ensure => running,
enable => true,
Expand Down
51 changes: 1 addition & 50 deletions spec/classes/config_spec.rb
Expand Up @@ -7,24 +7,8 @@
facts
end

context 'with default values for Redhat family release 6' do
context 'with defaults for all parameters' do
it { is_expected.to compile.with_all_deps }
it do
is_expected.to contain_group('caddy').with(
'ensure' => 'present',
'system' => 'true'
)
end
it do
is_expected.to contain_user('caddy').with(
'ensure' => 'present',
'shell' => '/sbin/nologin',
'gid' => 'caddy',
'system' => 'true',
'home' => '/etc/ssl/caddy',
'managehome' => 'true'
)
end
it do
is_expected.to contain_file('/etc/ssl/caddy/.caddy').with(
'ensure' => 'directory',
Expand Down Expand Up @@ -72,39 +56,6 @@
'require' => 'User[caddy]'
)
end

case facts[:os]['release']['major']
when '7'
it do
is_expected.to contain_file('/etc/systemd/system/caddy.service').with(
'ensure' => 'file',
'owner' => 'root',
'group' => 'root',
'mode' => '0744',
'content' => %r{User=caddy},
'notify' => 'Exec[systemctl-daemon-reload]',
'require' => 'Class[Caddy::Package]'
)
end
it do
is_expected.to contain_exec('systemctl-daemon-reload').with(
'refreshonly' => 'true',
'path' => '/usr/bin:/usr/sbin:/bin:/usr/local/bin',
'command' => 'systemctl daemon-reload'
)
end
when '6'
it do
is_expected.to contain_file('/etc/init.d/caddy').with(
'ensure' => 'file',
'owner' => 'root',
'group' => 'root',
'mode' => '0744',
'content' => %r{DAEMONUSER=caddy},
'require' => 'Class[Caddy::Package]'
)
end
end
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/classes/init_spec.rb
Expand Up @@ -11,6 +11,22 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('caddy') }
it { is_expected.to contain_class('caddy::params') }
it do
is_expected.to contain_group('caddy').with(
'ensure' => 'present',
'system' => 'true'
)
end
it do
is_expected.to contain_user('caddy').with(
'ensure' => 'present',
'shell' => '/sbin/nologin',
'gid' => 'caddy',
'system' => 'true',
'home' => '/etc/ssl/caddy',
'managehome' => 'true'
)
end
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/classes/service_spec.rb
Expand Up @@ -15,6 +15,38 @@
'enable' => 'true'
)
end
case facts[:os]['release']['major']
when '7'
it do
is_expected.to contain_file('/etc/systemd/system/caddy.service').with(
'ensure' => 'file',
'owner' => 'root',
'group' => 'root',
'mode' => '0744',
'content' => %r{User=caddy},
'notify' => 'Exec[systemctl-daemon-reload]',
'require' => 'Class[Caddy::Package]'
)
end
it do
is_expected.to contain_exec('systemctl-daemon-reload').with(
'refreshonly' => 'true',
'path' => '/usr/bin:/usr/sbin:/bin:/usr/local/bin',
'command' => 'systemctl daemon-reload'
)
end
when '6'
it do
is_expected.to contain_file('/etc/init.d/caddy').with(
'ensure' => 'file',
'owner' => 'root',
'group' => 'root',
'mode' => '0744',
'content' => %r{DAEMONUSER=caddy},
'require' => 'Class[Caddy::Package]'
)
end
end
end
end
end
Expand Down