Skip to content

Commit 7736608

Browse files
optiz0rekohl
authored andcommitted
Support multiple envs_dir directories
This module adds support for the puppet environmentpath setting to be configured using multiple directories. An example use-case is where r10k is in use to deploy some but not all environments, to avoid unmanaged environments being purged by r10k. Directories (whether one, or multiple) are passed as an Array of Stdlib::Absolutepath values. This is a breaking change, as a single string will no longer be accepted. - Each listed environmentpath directory will be created and managed by puppet - The default post-receive hook script uses the first listed directory in `envs_dir` to create initial environments to maintain backward compatibility. Tests are included to ensure that all listed directories are created and managed. Fixes #708
1 parent 19be9b8 commit 7736608

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

manifests/init.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
#
289289
# $server_environment_timeout:: Timeout for cached compiled catalogs (10s, 5m, ...)
290290
#
291-
# $server_envs_dir:: Directory that holds puppet environments
291+
# $server_envs_dir:: List of directories which hold puppet environments
292292
#
293293
# $server_envs_target:: Indicates that $envs_dir should be
294294
# a symbolic link to this target
@@ -656,7 +656,7 @@
656656
String $server_environments_owner = $puppet::params::server_environments_owner,
657657
Optional[String] $server_environments_group = $puppet::params::server_environments_group,
658658
Pattern[/^[0-9]{3,4}$/] $server_environments_mode = $puppet::params::server_environments_mode,
659-
Stdlib::Absolutepath $server_envs_dir = $puppet::params::server_envs_dir,
659+
Array[Stdlib::Absolutepath, 1] $server_envs_dir = $puppet::params::server_envs_dir,
660660
Optional[Stdlib::Absolutepath] $server_envs_target = $puppet::params::server_envs_target,
661661
Variant[Undef, String[0], Array[Stdlib::Absolutepath]] $server_common_modules_path = $puppet::params::server_common_modules_path,
662662
Pattern[/^[0-9]{3,4}$/] $server_git_repo_mode = $puppet::params::server_git_repo_mode,

manifests/params.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@
241241
$server_environments_group = $root_group
242242
$server_environments_mode = '0755'
243243
# Where we store our puppet environments
244-
$server_envs_dir = "${codedir}/environments"
244+
$server_envs_dir = ["${codedir}/environments"]
245245
$server_envs_target = undef
246246
# Modules in this directory would be shared across all environments
247-
$server_common_modules_path = unique(["${server_envs_dir}/common", "${codedir}/modules", "${sharedir}/modules", '/usr/share/puppet/modules'])
247+
$server_common_modules_path = unique(["${server_envs_dir[0]}/common", "${codedir}/modules", "${sharedir}/modules", '/usr/share/puppet/modules'])
248248

249249
# Dynamic environments config, ignore if the git_repo is 'false'
250250
# Path to the repository

manifests/server.pp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@
7070
#
7171
# $environments_mode:: Environments directory mode.
7272
#
73-
# $envs_dir:: Directory that holds puppet environments
73+
# $envs_dir:: List of directories that hold puppet environments
74+
# All listed directories will be created and attributes managed,
75+
# but only the first listed path will be used to populate
76+
# environments from git repo branches.
7477
#
7578
# $envs_target:: Indicates that $envs_dir should be
7679
# a symbolic link to this target
@@ -371,7 +374,7 @@
371374
String $environments_owner = $puppet::server_environments_owner,
372375
Optional[String] $environments_group = $puppet::server_environments_group,
373376
Pattern[/^[0-9]{3,4}$/] $environments_mode = $puppet::server_environments_mode,
374-
Stdlib::Absolutepath $envs_dir = $puppet::server_envs_dir,
377+
Array[Stdlib::Absolutepath, 1] $envs_dir = $puppet::server_envs_dir,
375378
Optional[Stdlib::Absolutepath] $envs_target = $puppet::server_envs_target,
376379
Variant[Undef, String[0], Array[Stdlib::Absolutepath]] $common_modules_path = $puppet::server_common_modules_path,
377380
Pattern[/^[0-9]{3,4}$/] $git_repo_mode = $puppet::server_git_repo_mode,

manifests/server/config.pp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
$server_external_nodes = $puppet::server::external_nodes
3737
$server_environment_timeout = $puppet::server::environment_timeout
3838
$trusted_external_command = $puppet::server::trusted_external_command
39+
$primary_envs_dir = $puppet::server::envs_dir[0]
3940

4041
if $server_external_nodes and $server_external_nodes != '' {
4142
class{ 'puppet::server::enc':
@@ -56,7 +57,7 @@
5657

5758
puppet::config::main {
5859
'reports': value => $puppet::server::reports;
59-
'environmentpath': value => $puppet::server::envs_dir;
60+
'environmentpath': value => $puppet::server::envs_dir.join(':');
6061
}
6162
if $puppet::server::hiera_config and !empty($puppet::server::hiera_config){
6263
puppet::config::main {
@@ -258,7 +259,7 @@
258259
mode => $puppet::server::git_repo_mode,
259260
user => $puppet::server::git_repo_user,
260261
group => $puppet::server::git_repo_group,
261-
require => File[$puppet::vardir, $puppet::server::envs_dir],
262+
require => File[$puppet::vardir, $primary_envs_dir],
262263
}
263264

264265
$git_branch_map = $puppet::server::git_branch_map

spec/classes/puppet_server_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,23 @@
674674
it { should contain_puppet__config__master('trusted_external_command').with_value('/usr/local/sbin/trusted_external_command') }
675675
end
676676
end
677+
678+
describe 'with multiple environment paths' do
679+
let(:params) do
680+
super().merge(
681+
server_envs_dir: ['/etc/puppetlabs/code/environments/', '/etc/puppetlabs/code/unmanaged-environments/'],
682+
server_git_repo_path: '/test/puppet',
683+
server_post_hook_name: 'post-receive',
684+
server_git_repo: true,
685+
)
686+
end
687+
688+
it { should contain_puppet__config__main('environmentpath').with_value('/etc/puppetlabs/code/environments/:/etc/puppetlabs/code/unmanaged-environments/') }
689+
it { should contain_file('/etc/puppetlabs/code/environments/') }
690+
it { should contain_file('/etc/puppetlabs/code/unmanaged-environments/') }
691+
it { should contain_git__repo('puppet_repo').that_requires('File[/etc/puppetlabs/code/environments/]') }
692+
it { should contain_file('/test/puppet/hooks/post-receive').with_content(/ENVIRONMENT_BASEDIR\s=\s"\/etc\/puppetlabs\/code\/environments\/"/) }
693+
end
677694
end
678695
end
679696
end

templates/server/post-receive.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $stdout.sync = true
1010
$stderr.sync = true
1111

1212
# Set this to where you want to keep your environments
13-
ENVIRONMENT_BASEDIR = "<%= scope.lookupvar("puppet::server::envs_dir") %>"
13+
ENVIRONMENT_BASEDIR = "<%= scope.lookupvar("puppet::server::config::primary_envs_dir") %>"
1414

1515
# post-receive hooks set GIT_DIR to the current repository. If you want to
1616
# clone from a non-local repository, set this to the URL of the repository,

0 commit comments

Comments
 (0)