From f52442e5d0b11b4368252dcaf53a3deeaf197fa2 Mon Sep 17 00:00:00 2001 From: William Yardley Date: Tue, 1 Nov 2016 21:03:10 -0700 Subject: [PATCH] Add 'require' for parent dir of upstream, map, and geo configs as well (#942) --- manifests/resource/geo.pp | 6 ++++-- manifests/resource/mailhost.pp | 12 +++++++----- manifests/resource/map.pp | 6 ++++-- manifests/resource/upstream.pp | 9 ++++++--- spec/defines/resource_geo_spec.rb | 1 + spec/defines/resource_mailhost_spec.rb | 1 + spec/defines/resource_map_spec.rb | 1 + spec/defines/resource_upstream_spec.rb | 2 +- 8 files changed, 25 insertions(+), 13 deletions(-) diff --git a/manifests/resource/geo.pp b/manifests/resource/geo.pp index 0fd9de39d..6b535f8f5 100644 --- a/manifests/resource/geo.pp +++ b/manifests/resource/geo.pp @@ -16,7 +16,7 @@ # [*proxy_recursive*] - Changes the behavior of address acquisition when # specifying trusted proxies via 'proxies' directive # [*proxies*] - Hash of network->value mappings. - +# # Actions: # # Requires: @@ -74,6 +74,7 @@ if ($proxy_recursive != undef) { validate_bool($proxy_recursive) } $root_group = $::nginx::config::root_group + $conf_dir = "${::nginx::config::conf_dir}/conf.d" $ensure_real = $ensure ? { 'absent' => 'absent', @@ -86,9 +87,10 @@ mode => '0644', } - file { "${::nginx::config::conf_dir}/conf.d/${name}-geo.conf": + file { "${conf_dir}/${name}-geo.conf": ensure => $ensure_real, content => template('nginx/conf.d/geo.erb'), notify => Class['::nginx::service'], + require => File[$conf_dir], } } diff --git a/manifests/resource/mailhost.pp b/manifests/resource/mailhost.pp index 01744673f..1e9566422 100644 --- a/manifests/resource/mailhost.pp +++ b/manifests/resource/mailhost.pp @@ -130,7 +130,8 @@ validate_string($xclient) validate_array($server_name) - $config_file = "${::nginx::config::conf_dir}/conf.mail.d/${name}.conf" + $config_dir = "${::nginx::config::conf_dir}/conf.mail.d" + $config_file = "${config_dir}/${name}.conf" # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled # and support does not exist for it in the kernel. @@ -146,10 +147,11 @@ } concat { $config_file: - owner => 'root', - group => $root_group, - mode => '0644', - notify => Class['::nginx::service'], + owner => 'root', + group => $root_group, + mode => '0644', + notify => Class['::nginx::service'], + require => File[$config_dir], } if (($ssl_port == undef) or ($listen_port + 0) != ($ssl_port + 0)) { diff --git a/manifests/resource/map.pp b/manifests/resource/map.pp index 34ed456f6..e086652b3 100644 --- a/manifests/resource/map.pp +++ b/manifests/resource/map.pp @@ -10,7 +10,7 @@ # [*mappings*] - Hash of map lookup keys and resultant values # [*hostnames*] - Indicates that source values can be hostnames with a # prefix or suffix mask. - +# # Actions: # # Requires: @@ -81,6 +81,7 @@ if ($default != undef) { validate_string($default) } $root_group = $::nginx::config::root_group + $conf_dir = "${::nginx::config::conf_dir}/conf.d" $ensure_real = $ensure ? { 'absent' => absent, @@ -93,9 +94,10 @@ mode => '0644', } - file { "${::nginx::config::conf_dir}/conf.d/${name}-map.conf": + file { "${conf_dir}/${name}-map.conf": ensure => $ensure_real, content => template('nginx/conf.d/map.erb'), notify => Class['::nginx::service'], + require => File[$conf_dir], } } diff --git a/manifests/resource/upstream.pp b/manifests/resource/upstream.pp index 1aea09a07..8869ea8e0 100644 --- a/manifests/resource/upstream.pp +++ b/manifests/resource/upstream.pp @@ -77,15 +77,18 @@ default => 'conf.d', } + $conf_dir = "${::nginx::config::conf_dir}/${conf_dir_real}" + Concat { owner => 'root', group => $root_group, mode => '0644', } - concat { "${::nginx::config::conf_dir}/${conf_dir_real}/${name}-upstream.conf": - ensure => $ensure_real, - notify => Class['::nginx::service'], + concat { "${conf_dir}/${name}-upstream.conf": + ensure => $ensure_real, + notify => Class['::nginx::service'], + require => File[$conf_dir], } # Uses: $name, $upstream_cfg_prepend diff --git a/spec/defines/resource_geo_spec.rb b/spec/defines/resource_geo_spec.rb index dbacd5b1d..80ba737c6 100644 --- a/spec/defines/resource_geo_spec.rb +++ b/spec/defines/resource_geo_spec.rb @@ -27,6 +27,7 @@ describe 'basic assumptions' do let(:params) { default_params } + it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").that_requires('File[/etc/nginx/conf.d]') } it do is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with( 'owner' => 'root', diff --git a/spec/defines/resource_mailhost_spec.rb b/spec/defines/resource_mailhost_spec.rb index 5a8521c5e..f0296c2b0 100644 --- a/spec/defines/resource_mailhost_spec.rb +++ b/spec/defines/resource_mailhost_spec.rb @@ -15,6 +15,7 @@ describe 'basic assumptions' do let(:params) { default_params } it { is_expected.to contain_class('nginx::config') } + it { is_expected.to contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").that_requires('File[/etc/nginx/conf.mail.d]') } it do is_expected.to contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").with('owner' => 'root', 'group' => 'root', diff --git a/spec/defines/resource_map_spec.rb b/spec/defines/resource_map_spec.rb index eeeeeb6d7..e66570c1f 100644 --- a/spec/defines/resource_map_spec.rb +++ b/spec/defines/resource_map_spec.rb @@ -27,6 +27,7 @@ describe 'basic assumptions' do let(:params) { default_params } + it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").that_requires('File[/etc/nginx/conf.d]') } it do is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with( 'owner' => 'root', diff --git a/spec/defines/resource_upstream_spec.rb b/spec/defines/resource_upstream_spec.rb index e9cc1fcc1..b0d4dd272 100644 --- a/spec/defines/resource_upstream_spec.rb +++ b/spec/defines/resource_upstream_spec.rb @@ -27,7 +27,7 @@ describe 'basic assumptions' do let(:params) { default_params } - it { is_expected.to contain_concat("/etc/nginx/conf.d/#{title}-upstream.conf") } + it { is_expected.to contain_concat("/etc/nginx/conf.d/#{title}-upstream.conf").that_requires('File[/etc/nginx/conf.d]') } it { is_expected.to contain_concat__fragment("#{title}_upstream_header").with_content(%r{upstream #{title}}) } it do