Pushing out all templates in a directory.

490 views
Skip to first unread message

Douglas Garstang

unread,
Jul 16, 2010, 1:35:45 PM7/16/10
to Puppet Users
I'm guessing you can't use the content attribute when pushing out all
files in a directory...

file {
"/etc/nagios/conf.d":
content => template("nagios/etc/nagios/conf.d"),
#source => "puppet:///nagios/etc/nagios/conf.d",
recurse => true,
purge => true,
force => true,
ignore => ".svn";
}

This returns the error:
Could not retrieve catalog from remote server: Error 400 on SERVER: Is
a directory - /etc/puppet/modules/nagios/templates/etc/nagios/conf.d
at /etc/puppet/modules/nagios/manifests/server/config.pp:11 on node
rmon01.xxx.xxx.com.

That's really frustrating. I wanted to easily manage all the nagios
config files, and it looks like I can't now. If I uncomment the source
line, and push our files, it works.

Doug.

Alan Barrett

unread,
Jul 16, 2010, 2:09:40 PM7/16/10
to puppet...@googlegroups.com
On Fri, 16 Jul 2010, Douglas Garstang wrote:
> I'm guessing you can't use the content attribute when pushing out all
> files in a directory...
>
> file {
> "/etc/nagios/conf.d":
> content => template("nagios/etc/nagios/conf.d"),
> #source => "puppet:///nagios/etc/nagios/conf.d",
> recurse => true,
> purge => true,
> force => true,
> ignore => ".svn";
> }

You can't use "content" with recursion. You can use "source" with
recursion. You can also override certain files in a recursively managed
directory:

file { "/some/dir":
ensure => directory, recurse => inf,


purge => true, force => true,

source => ...
}
file { "/some/dir/subdir/somefile":
ensure => file,
content => template(...),
}

You can also use the hostname or fqdn as part of the name of the source:

source => "puppet:///modules/mymodule/somedir.${fqdn}"

> That's really frustrating. I wanted to easily manage all the nagios
> config files, and it looks like I can't now. If I uncomment the source
> line, and push our files, it works.

I don't understand how you expected a single template to be able to
populate an entire directory, but if you really need to do this (as
opposed to letting each template create a single file), then I suppose
you could make the template emit some kind of bundle with special
delimiters to separate one embedded file from the next (the moral
equivalent of a tar or shar archive):

file { "/stagingarea/bundle":
content => template(...)
}
exec { "split bundle into files":
require => "/stagingarea/bundle",
command => "some script to unpack the bundle from the
staging area and create the files that
you really want",
onlyif => "some script to check whether the real files
are out of sync with the bundle",
}

Oh, after writing the above I realised that you probably want a
single template per target file, in the conventional way, but that
you want an easy way of saying "all templates in this directory".
You could probably do this using the "generate" function (to return
a list of files on the puppetmaster), and a definition (to create
one target file per result returned by "generate"), but I am not
sure of the details.

--apb (Alan Barrett)

Reply all
Reply to author
Forward
0 new messages