Recursively templating files in a directory

1,665 views
Skip to first unread message

Pete Emerson

unread,
Jul 8, 2009, 6:46:09 PM7/8/09
to Puppet Users
Suppose I have 100 files distributed recursively:

file { "/var/sample":
                source => "puppet:///files/sample",
                ensure => directory,
                recurse => true
        }

What I'd like to do is have all files inside the directory be templated:

file { "/var/sample":
                content => template("/var/lib/puppet/files/sample"),
                ensure => directory,
                recurse => true
        }

This attempt doesn't work (I'm running 0.24), and I don't want to specify 100 separate file definitions in my manifest. What's the right approach to recursively templating files?

Thanks,
Pete

David Schmitt

unread,
Jul 9, 2009, 3:18:40 PM7/9/09
to puppet...@googlegroups.com

The simplest approach would be a define:

define templated_sample() {
file { "/var/sample/${name}":
content => template("sample/${name}");
}
}

and use an array:

templated_sample{["file1","file2","dir/file3"]:}

Since functions are evaluated on the server, you can create the array
programatically from the list of templates:

$files = split("\0", generate("find", "/var/lib/puppet/files/sample",
"-type", "f", "-print0"))

You'd need another define+array for the directories. But that's just
more of the same...

Regards, DavidS

Reply all
Reply to author
Forward
0 new messages