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

V4 #135

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

V4 #135

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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ Value of the graph option in puppet.conf.

- *Default*: false

---
#### dns_alt_names (type: Optional[String])
Value of the dns_alt_names option in puppet.conf.

- *Default*: undef

---
#### agent_sysconfig_path (type: String)
The absolute path to the puppet agent sysconfig file.
Expand Down Expand Up @@ -187,9 +193,3 @@ external_nodes option in puppet.conf and the node_terminus option will
be set to 'exec'.

- *Default*: undef

---
#### dns_alt_names (type: Optional[String])
Value of the dns_alt_names option in puppet.conf.

- *Default*: undef
21 changes: 15 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
String $server = 'puppet',
String $ca_server = 'puppet',
String $env = $environment,
Optional[String] $dns_alt_names = undef,
Variant[Enum['true', 'false'], Boolean] $graph = false, #lint:ignore:quoted_booleans
String $agent_sysconfig_path = '/etc/sysconfig/puppet',
) {
Expand Down Expand Up @@ -87,15 +88,23 @@
}

$ini_settings = {
'server' => { setting => 'server', value => $server,},
'ca_server' => { setting => 'ca_server', value => $ca_server,},
'certname' => { setting => 'certname', value => $certname,},
'environment' => { setting => 'environment', value => $env,},
'trusted_node_data' => { setting => 'trusted_node_data', value => true,},
'graph' => { setting => 'graph', value => $graph,},
'server' => { setting => 'server', value => $server,},
'ca_server' => { setting => 'ca_server', value => $ca_server,},
'certname' => { setting => 'certname', value => $certname,},
'environment' => { setting => 'environment', value => $env,},
'trusted_node_data' => { setting => 'trusted_node_data', value => true,},
'graph' => { setting => 'graph', value => $graph,},
}
create_resources('ini_setting', $ini_settings, $ini_defaults)

if $dns_alt_names != undef {
ini_setting { 'dns_alt_names':
setting => 'dns_alt_names',
value => $dns_alt_names,
* => $ini_defaults,
}
}

file { 'puppet_config':
ensure => 'file',
path => $config_path,
Expand Down
27 changes: 15 additions & 12 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
#
# Manages puppetserver
#
class puppet::server(
class puppet::server (
Variant[Enum['true', 'false'], Boolean] $ca = false, #lint:ignore:quoted_booleans
Variant[Array[String, 1], Undef] $autosign_entries = undef,
String $sysconfig_path = '/etc/sysconfig/puppetserver',
String $memory_size = '2g', # only m and g are appropriate for unit
Optional[String] $enc = undef,
Optional[String] $dns_alt_names = undef,
) {

include ::puppet

$_ca = str2bool($ca)

if $sysconfig_path != undef {
validate_absolute_path($sysconfig_path)
}
Expand All @@ -34,7 +35,7 @@
'rundir' => { setting => 'rundir', value => '/var/run/puppetlabs/puppetserver',},
'pidfile' => { setting => 'pidfile', value => '/var/run/puppetlabs/puppetserver/puppetserver.pid',},
'codedir' => { setting => 'codedir', value =>'/etc/puppetlabs/code',},
'ca' => { setting => 'ca', value => $ca,},
'ca' => { setting => 'ca', value => $_ca,},
}

if $enc != undef {
Expand All @@ -47,15 +48,7 @@
$ini_enc_settings = {}
}

if $dns_alt_names != undef {
$ini_dns_alt_names_settings = {
'dns_alt_names' => { setting => 'dns_alt_names', value => $dns_alt_names },
}
} else {
$ini_dns_alt_names_settings = {}
}

$ini_settings_merged = $non_conditional_ini_settings + $ini_enc_settings + $ini_dns_alt_names_settings
$ini_settings_merged = $non_conditional_ini_settings + $ini_enc_settings
create_resources('ini_setting', $ini_settings_merged, $ini_defaults)

# Ensure that puppet.conf settings in [main] also trigger a restart of
Expand All @@ -81,6 +74,16 @@
notify => Service['puppetserver'],
}

file { 'puppetserver_ca_cfg':
ensure => 'file',
path => '/etc/puppetlabs/puppetserver/services.d/ca.cfg',
Copy link
Contributor

@Phil-Friderici Phil-Friderici Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if you want to support older puppetserver versions the path needs to be parameterized.
See voxpupuli/puppet-puppetserver#52 for details.

content => template('puppet/ca.cfg.erb'),
owner => 'root',
group => 'root',
mode => '0644',
notify => Service['puppetserver'],
}

service { 'puppetserver':
ensure => 'running',
enable => true,
Expand Down
6 changes: 4 additions & 2 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
end
end

it { should_not contain_ini_setting('dns_alt_names') }

it do
should contain_file('puppet_config').with({
:ensure => 'file',
Expand Down Expand Up @@ -187,7 +189,7 @@
end

describe 'with puppet.conf ini setting' do
%w(server ca_server certname graph).each do |setting|
%w(server ca_server certname graph dns_alt_names).each do |setting|
context "#{setting} set to a valid entry" do
# 'true' is used because it is acceptable to all of the above
# parameters. Some of the settings are strings and some are boolean and
Expand Down Expand Up @@ -266,7 +268,7 @@
:message => 'Error while evaluating a Resource Statement',
},
'strings' => {
:name => %w(certname cron_command server ca_server env),
:name => %w(certname cron_command server ca_server dns_alt_names env),
:valid => ['string'],
:invalid => [true, %w(array), { 'ha' => 'sh' }, 3, 2.42],
:message => 'Error while evaluating a Resource Statement',
Expand Down
93 changes: 61 additions & 32 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
require 'spec_helper'
describe 'puppet::server' do

ca_config_if_true = <<-END.gsub(/^\s+\|/, '')
|# This file is being maintained by Puppet.
|# DO NOT EDIT
|
|# To enable the CA service, leave the following line uncommented
|puppetlabs.services.ca.certificate-authority-service/certificate-authority-service
|# To disable the CA service, comment out the above line and uncomment the line below
|#puppetlabs.services.ca.certificate-authority-disabled-service/certificate-authority-disabled-service
END

ca_config_if_false = <<-END.gsub(/^\s+\|/, '')
|# This file is being maintained by Puppet.
|# DO NOT EDIT
|
|# To enable the CA service, leave the following line uncommented
|#puppetlabs.services.ca.certificate-authority-service/certificate-authority-service
|# To disable the CA service, comment out the above line and uncomment the line below
|puppetlabs.services.ca.certificate-authority-disabled-service/certificate-authority-disabled-service
END

# Filter out duplicate platforms
platforms = on_supported_os.select { |k, _v| !k.to_s.match(/^(RedHat|Scientific|OracleLinux)/i) }

Expand Down Expand Up @@ -36,7 +57,7 @@
end
end

%w(node_terminus external_nodes dns_alt_names).each do |setting|
%w(node_terminus external_nodes).each do |setting|
it { should_not contain_ini_setting(setting) }
end

Expand All @@ -57,6 +78,18 @@
})
end

it do
should contain_file('puppetserver_ca_cfg').with({
:ensure => 'file',
:path => '/etc/puppetlabs/puppetserver/services.d/ca.cfg',
:content => ca_config_if_false,
:owner => 'root',
:group => 'root',
:mode => '0644',
:notify => 'Service[puppetserver]',
})
end

puppetserver_sysconfig = File.read(fixtures('puppetserver_sysconfig'))
it do
should contain_file('puppetserver_sysconfig').with({
Expand All @@ -83,19 +116,39 @@
end

describe 'with ca' do
[true, 'true', false, 'false'].each do |value|
[true, 'true'].each do |value|
context "set to #{value} (as #{value.class})" do
let(:params) { { :ca => value } }

it do
should contain_file('puppetserver_ca_cfg').with({
:content => ca_config_if_true,
})
end

it do
should contain_ini_setting('ca').with({
:ensure => 'present',
:setting => 'ca',
:value => value,
:path => '/etc/puppetlabs/puppet/puppet.conf',
:section => 'master',
:require => 'File[puppet_config]',
:notify => 'Service[puppetserver]',
:value => true,
})
end
end
end

[false, 'false'].each do |value|
context "set to #{value} (as #{value.class})" do
let(:params) { { :ca => value } }

it do
should contain_file('puppetserver_ca_cfg').with({
:content => ca_config_if_false,
})
end

it do
should contain_ini_setting('ca').with({
:setting => 'ca',
:value => false,
})
end
end
Expand Down Expand Up @@ -132,24 +185,6 @@
end
end

describe 'with dns_alt_names' do
context 'set to a valid path' do
let(:params) { { :dns_alt_names => 'foo,foo1,foo1.example.com,foo.example.com' } }

it do
should contain_ini_setting('dns_alt_names').with({
:ensure => 'present',
:setting => 'dns_alt_names',
:value => 'foo,foo1,foo1.example.com,foo.example.com',
:path => '/etc/puppetlabs/puppet/puppet.conf',
:section => 'master',
:require => 'File[puppet_config]',
:notify => 'Service[puppetserver]',
})
end
end
end

describe 'with autosign_entries' do
context 'set to a valid array of strings' do
let(:params) { { :autosign_entries => ['*.example.org', '*.dev.example.org'] } }
Expand Down Expand Up @@ -179,12 +214,6 @@
:invalid => ['string', %w(array), { 'ha' => 'sh' }, 3, 2.42],
:message => 'Error while evaluating a Resource Statement',
},
'strings' => {
:name => %w(dns_alt_names),
:valid => ['string'],
:invalid => [true, %w(array), { 'ha' => 'sh' }, 3, 2.42],
:message => 'Error while evaluating a Resource Statement',
},
'non-empty array of strings' => {
:name => %w(autosign_entries),
:valid => [['array with one string'], %w(array with many strings)],
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/puppetserver_sysconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
JAVA_BIN="/usr/bin/java"

# Modify this if you'd like to change the memory allocation, enable JMX, etc
JAVA_ARGS="-Xms2g -Xmx2g -XX:MaxPermSize=256m"
JAVA_ARGS="-Xms2g -Xmx2g"

# These normally shouldn't need to be edited if using OS packages
USER="puppet"
Expand Down
15 changes: 15 additions & 0 deletions templates/ca.cfg.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is being maintained by Puppet.
# DO NOT EDIT

# To enable the CA service, leave the following line uncommented
<% if @_ca == true -%>
puppetlabs.services.ca.certificate-authority-service/certificate-authority-service
<% else -%>
#puppetlabs.services.ca.certificate-authority-service/certificate-authority-service
<% end -%>
# To disable the CA service, comment out the above line and uncomment the line below
<% if @_ca == true -%>
#puppetlabs.services.ca.certificate-authority-disabled-service/certificate-authority-disabled-service
<% else -%>
puppetlabs.services.ca.certificate-authority-disabled-service/certificate-authority-disabled-service
<% end -%>
2 changes: 1 addition & 1 deletion templates/puppetserver_sysconfig.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
JAVA_BIN="/usr/bin/java"

# Modify this if you'd like to change the memory allocation, enable JMX, etc
JAVA_ARGS="-Xms<%= @memory_size -%> -Xmx<%= @memory_size -%> -XX:MaxPermSize=256m"
JAVA_ARGS="-Xms<%= @memory_size -%> -Xmx<%= @memory_size -%>"

# These normally shouldn't need to be edited if using OS packages
USER="puppet"
Expand Down