> #Copy a file from the Puppet master. > # > #A good idea sourced from http://narrabilis.com/mybook/puppet/functions.pp > #Basically it's a little wrapper for the file type that's used to copy > #a file from the puppet master. 'module' and 'path' are the only > required > #parameters. > # > #PARAMETERS: > # - path The path to the source file to copy as relative to > modules/<module name>/files/. > # - module The name of the module to copy the file from. > # - mode Parameter passed directly to File type. > # - owner Parameter passed directly to File type. > # - group Parameter passed directly to File type. > # - ensure Parameter passed directly to File type. > define remotefile($path, $module, $owner = root, $group = root, $mode > = 0644, $ensure = present) { > file { $name: > ensure => $ensure, > mode => $mode, > owner => $owner, > group => $group, > source => "puppet:///modules/$module/$path", > } > } >
This compells me to elaborate a bit more. The problem with the above is that you cannot have a remotefile that doesn't care about the mode (i.e., let puppet accept whatever mode it finds on the client machine). If you just speicfy remotefile { "/etc/motd": module => "all" } the mode will be forced to 0644, which may not be what you want in edge cases. This is the pattern we use for this problem: define remotefile($mode = "") { if $mode != "" { File { mode => $mode } } file { $name: source => "puppet:///.../$name" } } Actually, our remotefile has similar support for about *all* parameters that "file" supports, except that owner and group indeed default to root (you would not want to not set those explicitly). Also note that the "path" parameter is optional in our implementation. Normally the URL uses $name, so if you need to override that behaviour, you can fall back to specifying the path. This is handled by if-else logic in the define. Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.