From 2ea5aac6362d5719bd26c2633663eb16858544b3 Mon Sep 17 00:00:00 2001 From: ceonizm Date: Sat, 18 Nov 2017 23:58:04 +0100 Subject: [PATCH] adding support for include directive in map (#1149) * adding support for include directive in map * change param name includes to include_files to keep naming consistent with the other manifests adding test to ensure empty value , single and multiple inclusions works correctly * fix rubocop offenses --- manifests/resource/map.pp | 10 ++++++++++ spec/defines/resource_map_spec.rb | 26 ++++++++++++++++++++++++++ templates/conf.d/map.erb | 3 +++ 3 files changed, 39 insertions(+) diff --git a/manifests/resource/map.pp b/manifests/resource/map.pp index 2cae672c6..a23b08727 100644 --- a/manifests/resource/map.pp +++ b/manifests/resource/map.pp @@ -10,6 +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. +# [*include_files*] - An array of external files to include # # Actions: # @@ -38,6 +39,14 @@ # ] # } # +# Sample Usage (using external include) +# +# nginx::resource::map { 'redirections': +# +# include_files => [ '/etc/nginx/conf.d/redirections.map'] +# +# } +# # Sample Hiera usage: # # nginx::string_mappings: @@ -67,6 +76,7 @@ Variant[Array, Hash] $mappings, Optional[String] $default = undef, Enum['absent', 'present'] $ensure = 'present', + Array[String] $include_files = [], Boolean $hostnames = false ) { if ! defined(Class['nginx']) { diff --git a/spec/defines/resource_map_spec.rb b/spec/defines/resource_map_spec.rb index 80159e4ef..790f7c5d7 100644 --- a/spec/defines/resource_map_spec.rb +++ b/spec/defines/resource_map_spec.rb @@ -52,6 +52,32 @@ value: true, match: ' hostnames;' }, + { + title: 'should not contain includes', + attr: 'include_files', + value: [], + notmatch: ' include ;' + }, + { + title: 'should contain includes', + attr: 'include_files', + value: ['/etc/includes/includes.map'], + match: ' include /etc/includes/includes.map;' + }, + { + title: 'should contain multiple includes', + attr: 'include_files', + value: [ + '/etc/includes/A.map', + '/etc/includes/B.map', + '/etc/includes/C.map' + ], + match: [ + ' include /etc/includes/A.map;', + ' include /etc/includes/B.map;', + ' include /etc/includes/C.map;' + ] + }, { title: 'should set default', attr: 'default', diff --git a/templates/conf.d/map.erb b/templates/conf.d/map.erb index c4944a8e8..07213d9fa 100644 --- a/templates/conf.d/map.erb +++ b/templates/conf.d/map.erb @@ -6,6 +6,9 @@ map <%= @string %> $<%= @name %> { <% if @default -%> default <%= @default %>; <% end -%> +<%- @include_files.each do |h| -%> + include <%= h %>; +<%- end -%> <% if @mappings.is_a?(Hash) -%> <%- field_width = @mappings.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%>