Skip to content

Commit 93c29f4

Browse files
Merge pull request #43 from crayfishx/add_environment_options
Add environment options
2 parents 9e4a913 + 210dac2 commit 93c29f4

File tree

4 files changed

+118
-4
lines changed

4 files changed

+118
-4
lines changed

README.markdown

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ running through webrick. In which case run a single puppet run using
2727
storeconfigs => true,
2828
}
2929

30-
### Master environments ###
30+
## Puppet Environments ##
31+
32+
Puppet 3.5 introduced a new way of handling Puppet environments known as _Directory Environments_. This is expected to become the default configuration as of Puppet 4.0, this module supports both methods.
33+
34+
### Config Method (default) ###
35+
36+
class { 'puppet::master': }
37+
3138
puppet::masterenv {'dev':
3239
modulepath => '/etc/puppet/evn/dev/modules',
3340
manifest => '/etc/puppet/env/dev/site.pp',
@@ -37,6 +44,15 @@ running through webrick. In which case run a single puppet run using
3744
manifest => '/etc/puppet/env/production/site.pp',
3845
}
3946

47+
### Directory method using _environmentpath_ ###
48+
49+
class { 'puppet::master':
50+
environments => 'directory',
51+
}
52+
53+
Optionally, an `environmentpath` parameter can be supplied to configure the base root of Puppet environments, this defaults to `$confdir/environments`
54+
55+
4056
## Agent ##
4157
class { 'puppet::agent':
4258
puppet_server => master.puppetlabs.vm,

manifests/master.pp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# ['modulepath'] - Module path to be served by the puppet master
99
# ['manifest'] - Manifest path
1010
# ['hiera_config'] - Hiera config file path
11+
# ['environments'] - Which environment method (directory or config)
12+
# ['environmentpath'] - Puppet environment base path (use with environments directory)
1113
# ['reports'] - Turn on puppet reports
1214
# ['storeconfigs'] - Use storedcofnigs
1315
# ['storeconfigs_dbserver'] - Puppetdb server
@@ -53,6 +55,8 @@
5355
$modulepath = $::puppet::params::modulepath,
5456
$manifest = $::puppet::params::manifest,
5557
$hiera_config = $::puppet::params::hiera_config,
58+
$environmentpath = $::puppet::params::environmentpath,
59+
$environments = $::puppet::params::environments,
5660
$reports = store,
5761
$storeconfigs = false,
5862
$storeconfigs_dbserver = $::puppet::params::storeconfigs_dbserver,
@@ -191,17 +195,33 @@
191195
section => 'master',
192196
}
193197

198+
case $environments {
199+
'config': {
200+
$setting_config='present'
201+
$setting_directory='absent'
202+
}
203+
'directory': {
204+
$setting_config='absent'
205+
$setting_directory='present'
206+
}
207+
default: { fail("Unknown value for environments ${environments}") }
208+
}
209+
194210
ini_setting {'puppetmastermodulepath':
195-
ensure => present,
211+
ensure => $setting_config,
196212
setting => 'modulepath',
197213
value => $modulepath,
198214
}
199-
200215
ini_setting {'puppetmastermanifest':
201-
ensure => present,
216+
ensure => $setting_config,
202217
setting => 'manifest',
203218
value => $manifest,
204219
}
220+
ini_setting {'puppetmasterenvironmentpath':
221+
ensure => $setting_directory,
222+
setting => 'environmentpath',
223+
value => $environmentpath,
224+
}
205225

206226
ini_setting {'puppetmasterhieraconfig':
207227
ensure => present,

manifests/params.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
$apache_serveradmin = 'root'
3030
$parser = 'current'
3131
$puppetdb_strict_validation = true
32+
$environments = 'config'
33+
34+
# Only used when environments == directory
35+
$environmentpath = '$confdir/environments'
3236

3337
case $::osfamily {
3438
'RedHat': {

spec/classes/puppet_master_spec.rb

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
should contain_class('puppet::passenger').with(
7575
:before => 'Anchor[puppet::master::end]'
7676
)
77+
should contain_ini_setting('puppetmasterenvironmentpath').with(
78+
:ensure => 'absent',
79+
:setting => 'environmentpath'
80+
)
7781
should contain_ini_setting('puppetmastermodulepath').with(
7882
:ensure => 'present',
7983
:section => 'master',
@@ -214,6 +218,9 @@
214218
should contain_class('puppet::passenger').with(
215219
:before => 'Anchor[puppet::master::end]'
216220
)
221+
should contain_ini_setting('puppetmasterenvironmentpath').with(
222+
:ensure => 'absent'
223+
)
217224
should contain_ini_setting('puppetmastermodulepath').with(
218225
:ensure => 'present',
219226
:section => 'master',
@@ -282,4 +289,71 @@
282289
should contain_anchor('puppet::master::end')
283290
}
284291
end
292+
context 'When environment handling is set to directory' do
293+
let(:facts) do
294+
{
295+
:osfamily => 'RedHat',
296+
:operatingsystem => 'RedHat',
297+
:operatingsystemrelease => '6',
298+
:concat_basedir => '/nde',
299+
}
300+
end
301+
let (:params) do {
302+
:environments => 'directory'
303+
}
304+
end
305+
306+
it {
307+
should contain_ini_setting('puppetmasterenvironmentpath').with(
308+
:ensure => 'present',
309+
:section => 'master',
310+
:setting => 'environmentpath',
311+
:path => '/etc/puppet/puppet.conf',
312+
:value => '$confdir/environments'
313+
)
314+
should contain_ini_setting('puppetmastermodulepath').with(
315+
:ensure => 'absent',
316+
:setting => 'modulepath'
317+
)
318+
should contain_ini_setting('puppetmastermanifest').with(
319+
:ensure => 'absent',
320+
:setting => 'manifest'
321+
)
322+
323+
}
324+
end
325+
context 'When environment handling is set to directory with specified environmentpath' do
326+
let(:facts) do
327+
{
328+
:osfamily => 'RedHat',
329+
:operatingsystem => 'RedHat',
330+
:operatingsystemrelease => '6',
331+
:concat_basedir => '/nde',
332+
}
333+
end
334+
let (:params) do {
335+
:environments => 'directory',
336+
:environmentpath => '/etc/puppetlabs/puppet/environments',
337+
}
338+
end
339+
340+
it {
341+
should contain_ini_setting('puppetmasterenvironmentpath').with(
342+
:ensure => 'present',
343+
:section => 'master',
344+
:setting => 'environmentpath',
345+
:path => '/etc/puppet/puppet.conf',
346+
:value => '/etc/puppetlabs/puppet/environments'
347+
)
348+
should contain_ini_setting('puppetmastermodulepath').with(
349+
:ensure => 'absent',
350+
:setting => 'modulepath'
351+
)
352+
should contain_ini_setting('puppetmastermanifest').with(
353+
:ensure => 'absent',
354+
:setting => 'manifest'
355+
)
356+
}
357+
end
358+
285359
end

0 commit comments

Comments
 (0)