1

I'm looking for the syntax to copy an entire templates directory inside a puppet module. (Eg: templates/webconfig/file1.erb, templates/webconfig/config/file2.erb)

I tried to copy in below syntax:

file {"$http_home_dir/webconfig": ensure => "directory", owner => "$http_user", group => "$http_group", content => template("webconfig"), recurse => true, require => File["$http_home_dir"]; } 

It doesn't worked. When i tried to use wildcard like below also, it didn't worked.

content => template("webconfig/*.erb"), 

Is there anything specific I'm missing

1 Answer 1

1

You can only copy files wholesale using the source parameter, which copies files as-is. The only way you can copy multiple templates is to use multiple file resources.

A way of shortening the amount of code you need is using a define resource type. For example, using Puppet 4 strict typing and the splat operator:

define myclass::webconfig ( String $file_path, Hash $attributes, String $template_path, ) { file { $file_path: ensure => file, content => template("${template_path}/${name}.erb"), * => $attributes, } } 

Which can be used as:

file { $http_home_dir: ensure => directory, owner => $http_user, group => $http_group, } myclass::webconfig { 'myfile': template_path => 'webconfig', file_path => "${http_home_dir}/webconfig", attributes => { owner => $http_user, group => $http_group, require => File[$http_home_dir], } } 

Which will place a file at $http_dir/webconfig/myfile with the contents of template webconfig/myfile.erb.

You can also pass an array of file names, like so:

$my_files = [ 'myfile', 'myotherfile', 'mythirdfile', 'foobarfozbaz' ] file { $http_home_dir: ensure => directory, owner => $http_user, group => $http_group, } myclass::webconfig { $my_files: template_path => 'webconfig', file_path => "${http_dir}/webconfig", attributes => { owner => $http_user, group => $http_group, require => File[$http_home_dir], } } 
2
  • 1
    Thanks @Craig Is the above scenario possible in Puppet 3.8? Commented May 15, 2017 at 10:35
  • Puppet 3 is EOL - it may be possible in Puppet 3.8 with --parser future but YMMV. It's guaranteed to with with Puppet 4. Commented May 15, 2017 at 10:37

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.