File tree Expand file tree Collapse file tree 4 files changed +64
-2
lines changed Expand file tree Collapse file tree 4 files changed +64
-2
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ The following parameters are available in the `elasticsearch` class:
129129* [ ` license ` ] ( #-elasticsearch--license )
130130* [ ` logdir ` ] ( #-elasticsearch--logdir )
131131* [ ` logdir_mode ` ] ( #-elasticsearch--logdir_mode )
132+ * [ ` logging_content ` ] ( #-elasticsearch--logging_content )
132133* [ ` manage_datadir ` ] ( #-elasticsearch--manage_datadir )
133134* [ ` manage_logdir ` ] ( #-elasticsearch--manage_logdir )
134135* [ ` manage_repo ` ] ( #-elasticsearch--manage_repo )
@@ -398,6 +399,14 @@ Mode directory that will be used for Elasticsearch logging (default 2750).
398399
399400Default value: ` '2750' `
400401
402+ ##### <a name =" -elasticsearch--logging_content " ></a >` logging_content `
403+
404+ Data type: ` Optional[Variant[String, Array]] `
405+
406+ Content to use for the logging configuration file (log4j2.properties).
407+
408+ Default value: ` undef `
409+
401410##### <a name =" -elasticsearch--manage_datadir " ></a >` manage_datadir `
402411
403412Data type: ` Boolean `
Original file line number Diff line number Diff line change 141141 $_tls_config = {}
142142 }
143143
144+ # Logging file
145+ if ! ($elasticsearch::logging_content =~ Undef ) {
146+ if $elasticsearch::logging_content =~ Array {
147+ $_log4j_content = $elasticsearch::logging_content .join(" \n " )
148+ } else {
149+ $_log4j_content = $elasticsearch::logging_content
150+ }
151+ file { "${elasticsearch::configdir}/log4j2.properties" :
152+ ensure => file ,
153+ content => $_log4j_content,
154+ notify => $elasticsearch::_notify_service ,
155+ require => Class[' elasticsearch::package' ],
156+ owner => ' root' ,
157+ group => $elasticsearch::elasticsearch_group ,
158+ mode => ' 0640' ,
159+ }
160+ }
161+
144162 # Generate Elasticsearch config
145163 $data =
146164 $elasticsearch::config + { ' path.data' => $elasticsearch::datadir } + { ' path.logs' => $elasticsearch::logdir } + $_tls_config
150168 content => template (" ${module_name} /etc/elasticsearch/elasticsearch.yml.erb" ),
151169 notify => $elasticsearch::_notify_service ,
152170 require => Class[' elasticsearch::package' ],
153- owner => $elasticsearch::elasticsearch_user ,
171+ owner => ' root ' ,
154172 group => $elasticsearch::elasticsearch_group ,
155- mode => ' 0440 ' ,
173+ mode => ' 0640 ' ,
156174 }
157175
158176 file { "${elasticsearch::configdir}/jvm.options" :
Original file line number Diff line number Diff line change 133133# @param logdir_mode
134134# Mode directory that will be used for Elasticsearch logging (default 2750).
135135#
136+ # @param logging_content
137+ # Content to use for the logging configuration file (log4j2.properties).
138+ #
136139# @param manage_datadir
137140# Enable datadir management (default true).
138141#
375378 Optional[String] $keystore_password = undef ,
376379 Optional[Stdlib::Absolutepath] $keystore_path = undef ,
377380 Stdlib::Filemode $logdir_mode = ' 2750' ,
381+ Optional[Variant[String, Array]] $logging_content = undef ,
378382 Boolean $package_hold = false ,
379383 Optional[Stdlib::Absolutepath] $private_key = undef ,
380384 Enum[' rsa' ,' dsa' ,' ec' ] $private_key_type = ' rsa' ,
Original file line number Diff line number Diff line change 7979 }
8080 end
8181
82+ it { expect ( subject ) . not_to contain_file ( '/etc/elasticsearch/log4j2.properties' ) }
83+
8284 context 'java installation' do
8385 let ( :pre_condition ) do
8486 <<-MANIFEST
346348 expect ( subject ) . not_to contain_file ( '/var/log/elasticsearch-log' )
347349 }
348350 end
351+
352+ context 'When using custom logging_content String' do
353+ let ( :params ) do
354+ default_params . merge (
355+ logging_content : '# Content'
356+ )
357+ end
358+
359+ it {
360+ expect ( subject ) . to contain_file ( '/etc/elasticsearch/log4j2.properties' ) .
361+ with ( ensure : 'file' , content : '# Content' )
362+ }
363+ end
364+
365+ context 'When using custom logging_content Array' do
366+ let ( :params ) do
367+ default_params . merge (
368+ logging_content : [
369+ '# Content Line 1' ,
370+ '# Content Line 2' ,
371+ ]
372+ )
373+ end
374+
375+ it {
376+ expect ( subject ) . to contain_file ( '/etc/elasticsearch/log4j2.properties' ) .
377+ with ( ensure : 'file' , content : "# Content Line 1\n # Content Line 2" )
378+ }
379+ end
349380 end
350381 end
351382 # rubocop:enable RSpec/MultipleMemoizedHelpers
You can’t perform that action at this time.
0 commit comments