From a61e010e8d24f2e44ab1ebba0cc4382b05ce9d37 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 16 Nov 2018 20:12:14 +0100 Subject: [PATCH] Remove dynamic and config environments Since Puppet 4 only directory environments are supported so this was mostly dead code. --- README.md | 18 +- manifests/init.pp | 18 +- manifests/params.pp | 7 - manifests/server.pp | 18 +- manifests/server/config.pp | 40 +--- manifests/server/env.pp | 94 -------- spec/classes/puppet_server_spec.rb | 103 +-------- spec/defines/puppet_server_env_spec.rb | 302 ------------------------- 8 files changed, 23 insertions(+), 577 deletions(-) delete mode 100644 manifests/server/env.pp delete mode 100644 spec/defines/puppet_server_env_spec.rb diff --git a/README.md b/README.md index b9a88d90..53946a8a 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,8 @@ any options that are not explicitly supported. ## Environments support -The module helps configure Puppet environments using directory environments on -Puppet 3.6+ and config environments on older versions. These are set up under -/etc/puppet/environments/ - change `server_environments` to define the list to -create, or use `puppet::server::env` for more control. When using directory -environments with R10K you need to set the `server_environments` parameter to an -empty array ie. `[]` to prevent `r10k deploy environments` from reporting an -error caused by the creation of top level environment directory(s). +The module helps configure Puppet environments using directory environments. +These are set up under /etc/puppetlabs/code/environments. ## Git repo support @@ -99,15 +94,6 @@ wrapper classes or even your ENC (if it supports param classes). For example: server_external_nodes => '', } - # The same example as above but overriding `server_environments` for R10K - class { '::puppet': - server => true, - server_foreman => false, - server_reports => 'store', - server_external_nodes => '', - server_environments => [], - } - # Want to integrate with an existing PuppetDB? class { '::puppet': server => true, diff --git a/manifests/init.pp b/manifests/init.pp index 09ab9f6b..e120ad6d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -231,26 +231,13 @@ # # $server_git_repo:: Use git repository as a source of modules # -# $server_dynamic_environments:: Use $environment in the modulepath -# Deprecated when $server_directory_environments is true, -# set $server_environments to [] instead. -# -# $server_directory_environments:: Enable directory environments, defaulting to true -# with Puppet 3.6.0 or higher -# -# $server_environments:: Environments to setup (creates directories). -# Applies only when $server_dynamic_environments -# is false -# # $server_environments_owner:: The owner of the environments directory # # $server_environments_group:: The group owning the environments directory # # $server_environments_mode:: Environments directory mode. # -# $server_common_modules_path:: Common modules paths (only when -# $server_git_repo_path and $server_dynamic_environments -# are false) +# $server_common_modules_path:: Common modules paths # # $server_git_repo_path:: Git repository path # @@ -637,12 +624,9 @@ Optional[String] $server_config_version = $puppet::params::server_config_version, Integer[0] $server_connect_timeout = $puppet::params::server_connect_timeout, Boolean $server_git_repo = $puppet::params::server_git_repo, - Boolean $server_dynamic_environments = $puppet::params::server_dynamic_environments, - Boolean $server_directory_environments = $puppet::params::server_directory_environments, Boolean $server_default_manifest = $puppet::params::server_default_manifest, Stdlib::Absolutepath $server_default_manifest_path = $puppet::params::server_default_manifest_path, String $server_default_manifest_content = $puppet::params::server_default_manifest_content, - Array[String] $server_environments = $puppet::params::server_environments, String $server_environments_owner = $puppet::params::server_environments_owner, Optional[String] $server_environments_group = $puppet::params::server_environments_group, Pattern[/^[0-9]{3,4}$/] $server_environments_mode = $puppet::params::server_environments_mode, diff --git a/manifests/params.pp b/manifests/params.pp index 94213aba..0491a503 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -237,13 +237,6 @@ # Git branch to puppet env mapping for the post receive hook $server_git_branch_map = {} - # Static environments config, ignore if the git_repo or dynamic_environments is 'true' - # What environments do we have - $server_environments = ['development', 'production'] - # Dynamic environments config (deprecated when directory_environments is true) - $server_dynamic_environments = false - # Directory environments config - $server_directory_environments = true # Owner of the environments dir: for cases external service needs write # access to manage it. $server_environments_owner = $user diff --git a/manifests/server.pp b/manifests/server.pp index 97977be2..7d46efbe 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -62,17 +62,6 @@ # # $git_repo:: Use git repository as a source of modules # -# $dynamic_environments:: Use $environment in the modulepath -# Deprecated when $directory_environments is true, -# set $environments to [] instead. -# -# $directory_environments:: Enable directory environments, defaulting to true -# with Puppet 3.6.0 or higher -# -# $environments:: Environments to setup (creates directories). -# Applies only when $dynamic_environments -# is false -# # $environments_owner:: The owner of the environments directory # # $environments_group:: The group owning the environments directory @@ -84,9 +73,7 @@ # $envs_target:: Indicates that $envs_dir should be # a symbolic link to this target # -# $common_modules_path:: Common modules paths (only when -# $git_repo_path and $dynamic_environments -# are false) +# $common_modules_path:: Common modules paths # # $git_repo_path:: Git repository path # @@ -334,12 +321,9 @@ Integer[0] $connect_timeout = $::puppet::server_connect_timeout, Integer[0] $web_idle_timeout = $puppet::server_web_idle_timeout, Boolean $git_repo = $::puppet::server_git_repo, - Boolean $dynamic_environments = $::puppet::server_dynamic_environments, - Boolean $directory_environments = $::puppet::server_directory_environments, Boolean $default_manifest = $::puppet::server_default_manifest, Stdlib::Absolutepath $default_manifest_path = $::puppet::server_default_manifest_path, String $default_manifest_content = $::puppet::server_default_manifest_content, - Array[String] $environments = $::puppet::server_environments, String $environments_owner = $::puppet::server_environments_owner, Optional[String] $environments_group = $::puppet::server_environments_group, Pattern[/^[0-9]{3,4}$/] $environments_mode = $::puppet::server_environments_mode, diff --git a/manifests/server/config.pp b/manifests/server/config.pp index 640cc660..49740221 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -49,17 +49,13 @@ puppet::config::main { 'reports': value => $::puppet::server::reports; + 'environmentpath': value => $puppet::server::envs_dir; } if $::puppet::server::hiera_config and !empty($::puppet::server::hiera_config){ puppet::config::main { 'hiera_config': value => $::puppet::server::hiera_config; } } - if $puppet::server::directory_environments { - puppet::config::main { - 'environmentpath': value => $puppet::server::envs_dir; - } - } if $puppet::server::common_modules_path and !empty($puppet::server::common_modules_path) { puppet::config::main { 'basemodulepath': value => $puppet::server::common_modules_path, joiner => ':'; @@ -95,17 +91,6 @@ 'storeconfigs_backend': value => $server_storeconfigs_backend; } } - if !$::puppet::server::directory_environments and ($::puppet::server::git_repo or $::puppet::server::dynamic_environments) { - puppet::config::master { - 'manifest': value => "${::puppet::server::envs_dir}/\$environment/manifests/site.pp"; - 'modulepath': value => "${::puppet::server::envs_dir}/\$environment/modules"; - } - if $::puppet::server::config_version_cmd { - puppet::config::master { - 'config_version': value => $::puppet::server::config_version_cmd; - } - } - } $::puppet::server_additional_settings.each |$key,$value| { puppet::config::master { $key: value => $value } @@ -269,24 +254,19 @@ mode => $::puppet::server::git_repo_mode, require => Git::Repo['puppet_repo'], } + } + file { $puppet::sharedir: + ensure => directory, } - elsif ! $::puppet::server::dynamic_environments { - file { $puppet::sharedir: - ensure => directory, - } - if $::puppet::server::common_modules_path and $::puppet::server::common_modules_path != '' { - file { $::puppet::server::common_modules_path: - ensure => directory, - owner => $::puppet::server_environments_owner, - group => $::puppet::server_environments_group, - mode => $::puppet::server_environments_mode, - } + if $::puppet::server::common_modules_path and !empty($::puppet::server::common_modules_path) { + file { $::puppet::server::common_modules_path: + ensure => directory, + owner => $::puppet::server_environments_owner, + group => $::puppet::server_environments_group, + mode => $::puppet::server_environments_mode, } - - # setup empty directories for our environments - puppet::server::env {$::puppet::server::environments: } } ## Foreman diff --git a/manifests/server/env.pp b/manifests/server/env.pp deleted file mode 100644 index 6a918705..00000000 --- a/manifests/server/env.pp +++ /dev/null @@ -1,94 +0,0 @@ -# Set up a puppet environment -define puppet::server::env ( - $basedir = $::puppet::server::envs_dir, - $config_version = $::puppet::server::config_version_cmd, - $manifest = undef, - $manifestdir = undef, - $modulepath = undef, - $templatedir = undef, - $environment_timeout = $::puppet::server::environment_timeout, - $directory_environments = $::puppet::server::directory_environments, - $owner = $::puppet::server::environments_owner, - $group = $::puppet::server::environments_group, - $mode = $::puppet::server::environments_mode, -) { - - $default_modulepath = ["${basedir}/${name}/modules", $::puppet::server::common_modules_path] - if $modulepath == undef { - $custom_modulepath = false - $real_modulepath = $default_modulepath - } else { - $custom_modulepath = ($modulepath != $default_modulepath) - $real_modulepath = $modulepath - } - - file { "${basedir}/${name}": - ensure => directory, - owner => $owner, - group => $group, - mode => $mode, - } - - file { "${basedir}/${name}/modules": - ensure => directory, - owner => $owner, - group => $group, - mode => $mode, - } - - if $directory_environments { - file { "${basedir}/${name}/manifests": - ensure => directory, - owner => $owner, - group => $group, - mode => $mode, - } - - if $manifest or $config_version or $custom_modulepath or $environment_timeout { - file { "${basedir}/${name}/environment.conf": - ensure => file, - owner => $owner, - group => $group, - mode => '0644', - content => template('puppet/server/environment.conf.erb'), - } - } - } else { - if $manifest { - puppet::config::environment{"${name}_manifest": - key => 'manifest', - env => $name, - value => $manifest, - } - } - if $manifestdir { - puppet::config::environment{"${name}_manifestdir": - key => 'manifestdir', - env => $name, - value => $manifestdir, - } - } - if $real_modulepath { - puppet::config::environment{"${name}_modulepath": - key => 'modulepath', - env => $name, - value => $real_modulepath, - joiner => ':', - } - } - if $templatedir { - puppet::config::environment{"${name}_templatedir": - key => 'templatedir', - env => $name, - value => $templatedir, - } - } - if $config_version { - puppet::config::environment{"${name}_config_version": - key => 'config_version', - env => $name, - value => $config_version, - } - } - } -} diff --git a/spec/classes/puppet_server_spec.rb b/spec/classes/puppet_server_spec.rb index c38be053..568beabf 100644 --- a/spec/classes/puppet_server_spec.rb +++ b/spec/classes/puppet_server_spec.rb @@ -62,10 +62,10 @@ it { should contain_class('puppet::server::config') } it { should contain_puppet__config__main('reports').with_value('foreman') } it { should contain_puppet__config__main('hiera_config').with_value('$confdir/hiera.yaml') } - it { should contain_puppet__config__main('environmentpath').with_value("#{codedir}/environments") } + it { should contain_puppet__config__main('environmentpath').with_value(environments_dir) } it do should contain_puppet__config__main('basemodulepath') - .with_value(["#{codedir}/environments/common", "#{codedir}/modules", "#{sharedir}/modules", '/usr/share/puppet/modules']) + .with_value(["#{environments_dir}/common", "#{codedir}/modules", "#{sharedir}/modules", '/usr/share/puppet/modules']) .with_joiner(':') end it { should_not contain_puppet__config__main('default_manifest') } @@ -109,7 +109,6 @@ .that_requires(["Concat[#{conf_file}]", 'Exec[puppet_server_config-create_ssl_dir]']) end - it { should contain_puppet__config__main('environmentpath').with_value(environments_dir) } it { should contain_exec('puppet_server_config-generate_ca_cert').that_notifies('Service[puppetserver]') } it 'should set up the environments' do @@ -132,9 +131,6 @@ .with_owner('puppet') .with_group(nil) .with_mode('0755') - - should contain_puppet__server__env('development') - should contain_puppet__server__env('production') end it { should contain_concat(conf_file) } @@ -390,9 +386,6 @@ .with_content(/BRANCH_MAP = \{[^a-zA-Z=>]\}/) end - it { should_not contain_puppet__server__env('development') } - it { should_not contain_puppet__server__env('production') } - describe 'with a puppet git branch map' do let(:params) do super().merge(server_git_branch_map: { 'a' => 'b', 'c' => 'd' }) @@ -403,94 +396,16 @@ .with_content(/BRANCH_MAP = \{\n "a" => "b",\n "c" => "d",\n\}/) end end - - context 'with directory environments' do - let(:params) do - super().merge(server_directory_environments: true) - end - - it 'should configure puppet.conf' do - should_not contain_puppet__config__master('config_version') - - should contain_puppet__config__main('environmentpath').with_value(environments_dir) - end - end - - context 'with config environments' do - let(:params) do - super().merge(server_directory_environments: false) - end - - it 'should configure puppet.conf' do - should contain_puppet__config__master('manifest').with_value("#{environments_dir}/\$environment/manifests/site.pp") - should contain_puppet__config__master('modulepath').with_value("#{environments_dir}/\$environment/modules") - should contain_puppet__config__master('config_version').with_value("git --git-dir #{environments_dir}/\$environment/.git describe --all --long") - end - end end - describe 'with dynamic environments' do - let(:params) do - super().merge(server_dynamic_environments: true) - end - - context 'with directory environments' do - let(:params) do - super().merge( - server_directory_environments: true, - server_environments_owner: 'apache' - ) - end - - it 'should set up the environments directory' do - should contain_file(environments_dir) \ - .with_ensure('directory') \ - .with_owner('apache') - end - - it 'should configure puppet.conf' do - should contain_puppet__config__main('environmentpath').with_value(environments_dir) - should contain_puppet__config__main('basemodulepath').with_value(["#{environments_dir}/common", "#{codedir}/modules", "#{sharedir}/modules", '/usr/share/puppet/modules']) - end - - it { should_not contain_puppet__server__env('development') } - it { should_not contain_puppet__server__env('production') } - end - - context 'with no common modules directory' do - let(:params) do - super().merge( - server_directory_environments: true, - server_environments_owner: 'apache', - server_common_modules_path: '' - ) - end - - it { should_not contain_puppet__config__main('basemodulepath') } - end - - context 'with config environments' do - let(:params) do - super().merge( - server_directory_environments: false, - server_environments_owner: 'apache' - ) - end - - it 'should set up the environments directory' do - should contain_file(environments_dir) \ - .with_ensure('directory') \ - .with_owner('apache') - end - - it 'should configure puppet.conf' do - should contain_puppet__config__master('manifest').with_value("#{environments_dir}/\$environment/manifests/site.pp") - should contain_puppet__config__master('modulepath').with_value("#{environments_dir}/\$environment/modules") - end + context 'with directory environments owner' do + let(:params) { super().merge(server_environments_owner: 'apache') } + it { should contain_file(environments_dir).with_owner('apache') } + end - it { should_not contain_puppet__server__env('development') } - it { should_not contain_puppet__server__env('production') } - end + context 'with no common modules directory' do + let(:params) { super().merge(server_common_modules_path: '') } + it { should_not contain_puppet__config__main('basemodulepath') } end describe 'with SSL path overrides' do diff --git a/spec/defines/puppet_server_env_spec.rb b/spec/defines/puppet_server_env_spec.rb deleted file mode 100644 index 9055d71e..00000000 --- a/spec/defines/puppet_server_env_spec.rb +++ /dev/null @@ -1,302 +0,0 @@ -require 'spec_helper' - -describe 'puppet::server::env' do - on_os_under_test.each do |os, facts| - next if facts[:osfamily] == 'windows' - next if facts[:osfamily] == 'Archlinux' - context "on #{os}" do - if facts[:osfamily] == 'FreeBSD' - codedir = '/usr/local/etc/puppet' - confdir = '/usr/local/etc/puppet' - logdir = '/var/log/puppet' - rundir = '/var/run/puppet' - ssldir = '/var/puppet/ssl' - vardir = '/var/puppet' - sharedir = '/usr/local/share/puppet' - else - codedir = '/etc/puppetlabs/code' - confdir = '/etc/puppetlabs/puppet' - logdir = '/var/log/puppetlabs/puppet' - rundir = '/var/run/puppetlabs' - ssldir = '/etc/puppetlabs/puppet/ssl' - vardir = '/opt/puppetlabs/puppet/cache' - sharedir = '/opt/puppetlabs/puppet' - end - - let(:facts) { facts } - - let(:title) { 'foo' } - - context 'with no custom parameters' do - context 'with directory environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => true}" - end - - it 'should only deploy directories' do - should contain_file("#{codedir}/environments").with({ - :ensure => 'directory', - :owner => 'puppet', - :group => nil, - :mode => '0755', - }) - - should contain_file("#{codedir}/environments/foo").with({ - :ensure => 'directory', - :owner => 'puppet', - :group => nil, - :mode => '0755', - }) - - should contain_file("#{codedir}/environments/foo/manifests").with({ - :ensure => 'directory', - :owner => 'puppet', - :group => nil, - :mode => '0755', - }) - - should contain_file("#{codedir}/environments/foo/modules").with({ - :ensure => 'directory', - :owner => 'puppet', - :group => nil, - :mode => '0755', - }) - - should_not contain_file("#{codedir}/environments/foo/environment.conf") - should_not contain_concat__fragment('puppet.conf_foo') - end - end - - context 'with config environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => false}" - end - - it 'should add an env section' do - should contain_file("#{codedir}/environments/foo").with({ - :ensure => 'directory', - :owner => 'puppet', - :group => nil, - :mode => '0755', - }) - - should contain_file("#{codedir}/environments/foo/modules").with({ - :ensure => 'directory', - :owner => 'puppet', - :group => nil, - :mode => '0755', - }) - - should_not contain_puppet__config__environment('foo_manifest') - should_not contain_puppet__config__environment('foo_manifestdir') - should_not contain_puppet__config__environment('foo_templatedir') - should_not contain_puppet__config__environment('foo_config_version') - should contain_puppet__config__environment('foo_modulepath').with({ - 'key' => 'modulepath', - 'value' => ["#{codedir}/environments/foo/modules",["#{codedir}/environments/common","#{codedir}/modules","#{sharedir}/modules","/usr/share/puppet/modules"]], - 'joiner' => ':', - }) - - should_not contain_file("#{codedir}/environments/foo/environment.conf") - end - end - end - - context 'with server_config_version' do - context 'with directory environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => true, server_config_version => 'bar'}" - end - - it 'should set config_version in environment.conf' do - should contain_file("#{codedir}/environments/foo/environment.conf"). - with_content(%r{\Aconfig_version\s+= bar\n\z}) - end - end - - context 'with config environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => false, server_config_version => 'bar'}" - end - - it 'should add config_version to an env section' do - should_not contain_puppet__config__environment('foo_manifest') - should_not contain_puppet__config__environment('foo_manifestdir') - should_not contain_puppet__config__environment('foo_templatedir') - should contain_puppet__config__environment('foo_modulepath').with({ - 'key' => 'modulepath', - 'value' => ["#{codedir}/environments/foo/modules",["#{codedir}/environments/common","#{codedir}/modules","#{sharedir}/modules","/usr/share/puppet/modules"]], - 'joiner' => ':', - }) - should contain_puppet__config__environment('foo_config_version').with({ - 'key' => 'config_version', - 'value' => 'bar', - }) - end - end - end - - context 'with config_version' do - let :params do - { - :config_version => 'bar', - } - end - - context 'with directory environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => true}" - end - - it 'should set config_version in environment.conf' do - should contain_file("#{codedir}/environments/foo/environment.conf"). - with_content(%r{\Aconfig_version\s+= bar\n\z}) - end - end - - context 'with config environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => false}" - end - - it 'should add config_version to an env section' do - should_not contain_puppet__config__environment('foo_manifest') - should_not contain_puppet__config__environment('foo_manifestdir') - should_not contain_puppet__config__environment('foo_templatedir') - should contain_puppet__config__environment('foo_modulepath').with({ - 'key' => 'modulepath', - 'value' => ["#{codedir}/environments/foo/modules",["#{codedir}/environments/common","#{codedir}/modules","#{sharedir}/modules","/usr/share/puppet/modules"]], - 'joiner' => ':', - }) - should contain_puppet__config__environment('foo_config_version').with({ - 'key' => 'config_version', - 'value' => 'bar', - }) - end - end - - context 'with directory environments link' do - let :pre_condition do - "class {'puppet': server => true, server_envs_target => '/foo'}" - end - - it 'should produce a symbolic link "environments" in codedir' do - should contain_file("#{codedir}/environments"). - with_target('/foo'). - with_ensure('link') - end - end - end - - context 'with modulepath' do - let :params do - { - :modulepath => ['/etc/puppet/example/modules', '/etc/puppet/vendor/modules'], - } - end - - context 'with directory environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => true}" - end - - it 'should set modulepath in environment.conf' do - should contain_file("#{codedir}/environments/foo/environment.conf"). - with_content(%r{\Amodulepath\s+= /etc/puppet/example/modules:/etc/puppet/vendor/modules\n}) - end - end - end - - context 'with undef modulepath' do - let :params do - { - :modulepath => Undef.new, - } - end - - context 'with directory environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => true}" - end - - it { should_not contain_file("#{codedir}/environments/foo/environment.conf") } - end - end - - context 'with custom basedir' do - basedir = "#{codedir}/baz_environments" - let :params do - { - :basedir => basedir, - } - end - - context 'with directory environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => true}" - end - - it { should_not contain_file("#{codedir}/environments/foo/environment.conf") } - it { should_not contain_file("#{basedir}/foo/environment.conf") } - end - - context 'with config environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => false}" - end - - it 'should add modulepath with custom basedir to an env section' do - should_not contain_puppet__config__environment('foo_manifest') - should_not contain_puppet__config__environment('foo_manifestdir') - should_not contain_puppet__config__environment('foo_templatedir') - should_not contain_puppet__config__environment('foo_config_version') - should contain_puppet__config__environment('foo_modulepath').with({ - 'key' => 'modulepath', - 'value' => ["#{basedir}/foo/modules",["#{codedir}/environments/common","#{codedir}/modules","#{sharedir}/modules","/usr/share/puppet/modules"]], - 'joiner' => ':', - }) - end - end - end - - context 'with manifest' do - let :params do - { - :manifest => 'manifests/local.pp', - } - end - - context 'with directory environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => true}" - end - - it 'should set manifest in environment.conf' do - should contain_file("#{codedir}/environments/foo/environment.conf"). - with_content(%r{\Amanifest\s+= manifests/local.pp\n\z}) - end - end - end - - context 'with environment_timeout' do - let :params do - { - :environment_timeout => 'unlimited', - } - end - - context 'with directory environments' do - let :pre_condition do - "class {'puppet': server => true, server_directory_environments => true}" - end - - it 'should set environment_timeout in environment.conf' do - should contain_file("#{codedir}/environments/foo/environment.conf"). - with_content(%r{\Aenvironment_timeout\s+= unlimited\n\z}) - end - end - end - - end - end -end