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

Manage unit file via systemd::unit_file #566

Merged
merged 2 commits into from
Aug 19, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fixtures:
mcollective: https://github.com/choria-io/puppet-mcollective.git
choria: https://github.com/choria-io/puppet-choria.git
apt: https://github.com/puppetlabs/puppetlabs-apt.git
systemd: https://github.com/voxpupuli/puppet-systemd.git
cron_core: https://github.com/puppetlabs/puppetlabs-cron_core.git
yumrepo_core: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git
forge_modules:
Expand Down
2 changes: 0 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,10 @@

if $facts['os']['family'] == 'Gentoo' {
$webhook_service_file = '/etc/init.d/webhook'
$webhook_service_template = 'webhook.init.gentoo.erb'
$webhook_service_file_mode = '0755'
$webhook_background = true
} else {
$webhook_service_file = '/etc/systemd/system/webhook.service'
$webhook_service_template = 'webhook.service.erb'
$webhook_service_file_mode = '0644'
$webhook_background = false
}
Expand Down
28 changes: 11 additions & 17 deletions manifests/webhook.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$group = $r10k::params::webhook_group,
$background = $r10k::params::webhook_background,
$bin_template = $r10k::params::webhook_bin_template,
$service_template = $r10k::params::webhook_service_template,
$service_template = 'webhook.service.epp',
$service_file = $r10k::params::webhook_service_file,
$service_file_mode = $r10k::params::webhook_service_file_mode,
$use_mcollective = $r10k::params::webhook_use_mcollective,
Expand Down Expand Up @@ -48,43 +48,37 @@
ensure => $ensure_file,
owner => $user,
group => $group,
before => Service['webhook'],
before => Service['webhook.service'],
}

file { '/var/log/webhook':
ensure => $ensure_directory,
owner => $user,
group => $group,
force => $ensure,
before => Service['webhook'],
before => Service['webhook.service'],
}

file { '/var/run/webhook':
ensure => $ensure_directory,
owner => $user,
group => $group,
before => Service['webhook'],
}

file { 'webhook_init_script':
ensure => $ensure_file,
content => template("r10k/${service_template}"),
path => $service_file,
mode => $service_file_mode,
notify => Service['webhook'],
before => Service['webhook.service'],
}

file { 'webhook_bin':
ensure => $ensure_file,
content => template($bin_template),
path => '/usr/local/bin/webhook',
mode => '0755',
notify => Service['webhook'],
notify => Service['webhook.service'],
}

service { 'webhook':
ensure => $ensure_service,
enable => $ensure,
systemd::unit_file { 'webhook.service':
ensure => $ensure_file,
content => epp("${module_name}/${service_template}", { 'user' => $user }),
enable => $ensure,
active => $ensure,
}

# We don't remove the packages/ gem as
Expand All @@ -106,7 +100,7 @@
group => 'peadmin',
mode => '0644',
content => file("${r10k::params::puppetconf_path}/ssl/certs/pe-internal-peadmin-mcollective-client.pem",'/dev/null'),
notify => Service['webhook'],
notify => Service['webhook.service'],
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/webhook/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
mode => $configfile_mode,
path => $configfile,
content => template($yaml_template),
notify => Service['webhook'],
notify => Service['webhook.service'],
}

if $manage_symlink {
Expand Down
6 changes: 3 additions & 3 deletions manifests/webhook/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package { 'sinatra':
ensure => $sinatra_version,
provider => $provider,
notify => Service['webhook'],
notify => Service['webhook.service'],
}
}

Expand All @@ -19,15 +19,15 @@
package { 'webrick':
ensure => $webrick_version,
provider => $provider,
notify => Service['webhook'],
notify => Service['webhook.service'],
}
}

if !defined(Package['json']) {
package { 'json':
ensure => installed,
provider => $provider,
notify => Service['webhook'],
notify => Service['webhook.service'],
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
{
"name": "choria/mcollective",
"version_requirement": ">= 0.10.0 <1.0.0"
},
{
"name": "puppet/systemd",
"version_requirement": ">= 3.2.0 < 4.0.0"
}
],
"requirements": [
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/basic_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class {'r10k::webhook::config':
enable_ssl => false,
protected => false,
use_mcollective => false,
notify => Service['webhook'],
notify => Service['webhook.service'],
}

class {'r10k::webhook':
Expand Down
42 changes: 0 additions & 42 deletions spec/acceptance/nodesets/default.yml

This file was deleted.

2 changes: 1 addition & 1 deletion spec/acceptance/prefix_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class {'r10k::webhook::config':
prefix => true,
prefix_command => '/usr/local/bin/prefix_command.rb',
require => File['/usr/local/bin/prefix_command.rb'],
notify => Service['webhook'],
notify => Service['webhook.service'],
}
class {'r10k::webhook':
require => Class['r10k::webhook::config'],
Expand Down
24 changes: 12 additions & 12 deletions spec/classes/webhook/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -77,7 +77,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -140,7 +140,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end

Expand Down Expand Up @@ -185,7 +185,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end

Expand Down Expand Up @@ -230,7 +230,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -275,7 +275,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -320,7 +320,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -363,7 +363,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -408,7 +408,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -453,7 +453,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -521,7 +521,7 @@
owner: 'r10k',
group: 'r10k',
mode: '0600',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
end
Expand All @@ -540,7 +540,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down
31 changes: 20 additions & 11 deletions spec/classes/webhook/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
end

let :pre_condition do
"service { 'webhook': ensure => present,}"
"service { 'webhook.service': ensure => 'running'}"
end

context 'Puppet Enterprise 2016.4.2' do
context 'Puppet Enterprise 2019.8.7' do
let :params do
{
is_pe_server: true
}
end
let :facts do
facts.merge(
pe_server_version: '2016.4.2'
pe_server_version: '2019.8.7'
)
end

Expand All @@ -28,24 +28,33 @@
else
'puppet_gem'
end
it do
is_expected.to contain_package('sinatra').with(
ensure: '~> 1.0',
provider: provider
)
end
it { is_expected.to contain_package('sinatra').with(provider: provider) }
it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_package('webrick') }
it { is_expected.not_to contain_package('json') }
end
context 'Puppet FOSS 6' do
let :facts do
facts.merge(
is_pe: false,
puppetversion: '6.24.0'
)
end

context 'Puppet FOSS 4.x' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('sinatra').with(ensure: 'installed') }
it { is_expected.to contain_package('webrick').with(ensure: 'installed') }
it { is_expected.to contain_package('json').with(ensure: 'installed') }
end
context 'Puppet FOSS 7' do
let :facts do
facts.merge(
is_pe: false,
puppetversion: '4.8.0'
puppetversion: '7.10.0'
)
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('sinatra').with(ensure: 'installed') }
it { is_expected.to contain_package('webrick').with(ensure: 'installed') }
it { is_expected.to contain_package('json').with(ensure: 'installed') }
Expand Down
Loading