From a563a7db1319d74312cd8cd23813421218d8fea5 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Wed, 10 Jun 2015 13:51:37 +0200 Subject: [PATCH] implement content param for file resource this is a PR for [issue](https://github.com/elastic/puppet-logstash/issues/222), I tested it with puppet 3.8.1 on centos7, it is working fine. --- manifests/patternfile.pp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/manifests/patternfile.pp b/manifests/patternfile.pp index 13dcf531..aec23caf 100644 --- a/manifests/patternfile.pp +++ b/manifests/patternfile.pp @@ -39,25 +39,40 @@ # * Richard Pijnenburg # define logstash::patternfile ( - $source, + $content = '', + $source = '', $filename = '', ){ - - validate_re($source, '^puppet://', 'Source must be from a puppet fileserver (begin with puppet://)' ) - + if ($content == '') and ($source == '') { + fail('please specify $content or $source') + } + if ($content != '') and ($source != '') { + fail("you provided \$content with ${content} and \$source with ${source}, please only provide one of them") + } + unless ($source == ''){ + validate_re($source, '^puppet://', 'Source must be from a puppet fileserver (begin with puppet://)' ) + } $patterns_dir = "${logstash::configdir}/patterns" $filename_real = $filename ? { '' => inline_template('<%= @source.split("/").last %>'), default => $filename } - - file { "${patterns_dir}/${filename_real}": - ensure => 'file', - owner => $logstash::logstash_user, - group => $logstash::logstash_group, - mode => '0644', - source => $source, + unless ($content == ''){ + file { "${patterns_dir}/${filename_real}": + ensure => 'file', + owner => $logstash::logstash_user, + group => $logstash::logstash_group, + mode => '0644', + content => $content, + } + } else { + file { "${patterns_dir}/${filename_real}": + ensure => 'file', + owner => $logstash::logstash_user, + group => $logstash::logstash_group, + mode => '0644', + source => $source, + } } - }