Skip to content

Commit c4b2454

Browse files
Merge pull request #48 from crayfishx/dir_envs
Dir envs thanks
2 parents 5486895 + ad09a69 commit c4b2454

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

manifests/masterenv.pp

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,44 @@
1818
# manifest => 'dev'
1919
# }
2020
#
21-
define puppet::masterenv ($modulepath, $manifest, $puppet_conf = $::puppet::params::puppet_conf){
21+
define puppet::masterenv (
22+
$modulepath,
23+
$manifest,
24+
$puppet_conf = $::puppet::params::puppet_conf,
25+
$environments = $::puppet::master::environments,
26+
$environmentpath = $::puppet::master::environmentpath
27+
) {
28+
29+
case $environments {
30+
'directory': {
31+
$path = "${environmentpath}/${name}/environment.conf"
32+
$section = ''
33+
file { "${environmentpath}/${name}":
34+
ensure => directory,
35+
}
36+
}
37+
default: {
38+
$path = $puppet_conf
39+
$section = $name
40+
}
41+
}
42+
2243
Ini_setting {
23-
path => $puppet_conf,
44+
path => $path,
45+
section => $section,
2446
require => [File[$puppet_conf], Class['puppet::master']],
2547
notify => Service['httpd'],
2648
}
2749

28-
ini_setting {"masterenvmodule${name}":
29-
ensure => present,
30-
section => $name,
31-
setting => 'modulepath',
32-
value => $modulepath,
33-
}
34-
ini_setting {"masterenvmanifest${name}":
35-
ensure => present,
36-
section => $name,
37-
setting => 'manifest',
38-
value => $manifest,
50+
ini_setting {
51+
"masterenvmodule${name}":
52+
ensure => present,
53+
setting => 'modulepath',
54+
value => $modulepath;
55+
56+
"masterenvmanifest${name}":
57+
ensure => present,
58+
setting => 'manifest',
59+
value => $manifest;
3960
}
4061
}

spec/defines/puppet_masterenv_spec.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe 'puppet::masterenv', :type => :define do
4-
context "Create environment" do
4+
context "Create config environment" do
55
let :title do
66
'dev'
77
end
@@ -30,4 +30,38 @@
3030
)
3131
}
3232
end
33+
context "Create directory environment" do
34+
let :title do
35+
'dev'
36+
end
37+
38+
let :params do
39+
{
40+
:manifest => '/etc/puppet/environments/dev.pp',
41+
:modulepath => '/etc/puppet/environments/modules/',
42+
:puppet_conf => '/etc/puppet/puppet.conf',
43+
:environments => 'directory',
44+
:environmentpath => '/etc/puppet/environments'
45+
}
46+
end
47+
it {
48+
should contain_ini_setting("masterenvmodule#{title}").with(
49+
:ensure => 'present',
50+
:section => '',
51+
:setting => 'modulepath',
52+
:path => '/etc/puppet/environments/dev/environment.conf',
53+
:value => params[:modulepath]
54+
)
55+
should contain_ini_setting("masterenvmanifest#{title}").with(
56+
:ensure => 'present',
57+
:section => '',
58+
:setting => 'manifest',
59+
:path => '/etc/puppet/environments/dev/environment.conf',
60+
:value => params[:manifest]
61+
)
62+
should contain_file("/etc/puppet/environments/dev").with(
63+
:ensure => 'directory'
64+
)
65+
}
66+
end
3367
end

0 commit comments

Comments
 (0)