Getting puppet to manage logrotate

365 views
Skip to first unread message

kenneho

unread,
May 20, 2008, 7:46:32 AM5/20/08
to Puppet Users
Hi.


I'm trying to configure puppet to manage logrotate, and decided to
make a definition such as this:

define logrotate(owner = root, group = root, mode = 0644, ensure =
file, size = "1MB", rotate = 5, source) {

file { "logrotate_file":
name => "/etc/logrotate.d/$title",
content => template("logrotate-template.erb")
}

}

I put this code in logrotate.pp. Next, I added this to the node
configuration:

logrotate { "test003.txt":
source => "/home/kenneho/logtest.txt"
}


The logrotate-template.erb file looks like this:

<%= source %> {
missingok
notifempty
size <%= size %>
rotate <%= rotate %>
}


When executing this configuration on the client I get an error message
saying:
"Tue May 20 13:06:45 +0200 2008 Puppet (err): Could not retrieve
catalog: Failed to parse template logrotate-template.erb: Could not
find value for 'source' at /etc/puppet/manifests/classes/logrotate.pp:
6 on node <node>"

I'm not sure where the error may be. Is it not allowd to call
definitions directly from a node definition? Or must the definition be
included in a class?

Regards,
kenneho

Peter Meier

unread,
May 20, 2008, 8:03:28 AM5/20/08
to puppet...@googlegroups.com
Hi

> define logrotate(owner = root, group = root, mode = 0644, ensure =
> file, size = "1MB", rotate = 5, source) {
>
> file { "logrotate_file":
> name => "/etc/logrotate.d/$title",
> content => template("logrotate-template.erb")
> }
>
> }
>
> I put this code in logrotate.pp. Next, I added this to the node
> configuration:
>
> logrotate { "test003.txt":
> source => "/home/kenneho/logtest.txt"
> }
>
>
> The logrotate-template.erb file looks like this:
>
> <%= source %> {
> missingok
> notifempty
> size <%= size %>
> rotate <%= rotate %>
> }
>
>
> When executing this configuration on the client I get an error message
> saying:
> "Tue May 20 13:06:45 +0200 2008 Puppet (err): Could not retrieve
> catalog: Failed to parse template logrotate-template.erb: Could not
> find value for 'source' at /etc/puppet/manifests/classes/logrotate.pp:
> 6 on node <node>"
>
> I'm not sure where the error may be. Is it not allowd to call
> definitions directly from a node definition? Or must the definition be
> included in a class?


I rather supsect that your define is broken. If you didn't change your
define by pasting it to the mail, it should be:

define logrotate($owner = root, $group = root, $mode = 0644, $ensure
=file, $size = "1MB", $rotate = 5, $source) { [...] }

this might lead to the actual error you see.

greetings Pete

Mike Renfro

unread,
May 20, 2008, 8:57:38 AM5/20/08
to puppet...@googlegroups.com
On 5/20/2008 7:03 AM, Peter Meier wrote:

> I rather supsect that your define is broken. If you didn't change your
> define by pasting it to the mail, it should be:
>
> define logrotate($owner = root, $group = root, $mode = 0644, $ensure
> =file, $size = "1MB", $rotate = 5, $source) { [...] }
>
> this might lead to the actual error you see.

Use of 'source' may be an issue, too, or at least odd, since source is
already a built-in file attribute.
http://reductivelabs.com/trac/puppet/wiki/TypeReference#file

--
Mike Renfro / R&D Engineer, Center for Manufacturing Research,
931 372-3601 / Tennessee Technological University

kenneho

unread,
May 20, 2008, 9:39:10 AM5/20/08
to Puppet Users


On 20 Mai, 14:03, Peter Meier <peter.me...@immerda.ch> wrote:

> I rather supsect that your define is broken. If you didn't change your
> define by pasting it to the mail, it should be:
>
> define logrotate($owner = root, $group = root, $mode = 0644, $ensure
> =file, $size = "1MB", $rotate = 5, $source) { [...] }
>

This solved the problem. I referenced an example (page 52) in
Turnbull's Puppet book, and left out the "$" in the definition. But I
see now that this was incorrect.

In addition, I replaced the use of "source" with something else, just
in case of issues here.

Thanks for the help.


Regards,
kenneho
Reply all
Reply to author
Forward
0 new messages