Re: creating a list of files from an external define

225 views
Skip to first unread message

jcbollinger

unread,
Oct 26, 2012, 4:23:46 PM10/26/12
to puppet...@googlegroups.com


On Thursday, October 25, 2012 3:33:16 PM UTC-5, danielt wrote:

Puppet expects to find a definition with this name:


helper::files{

 
in this file:

[...] modules/helper/manifests/files.pp


 
[...] I usually had the install define within the class. But puppet-lint didn't like this so I thought outsourcing it to its own module would work out.


I'm not sure what you mean about putting the define in its own module, but doing so (correctly) without changing its name would have put it exactly where Puppet was looking for it.  Some people try to use "module" as a synonym for "file", but Puppet "modules" are structured collections of files containing class, resource, and data definitions, and arranged according to a standard directory structure.

The definition doesn't need to be in its own module, but it should be in its own file within the module (which is what puppet-lint was telling you), and it should identify itself by its fully-qualified name.  Anyone outside the module must reference it by that fully-qualified name.  Classes and resources in the same module ought to be able to reference it by its name relative to the module, but they should reference it by its fully-qualified name, too.


John

danielt

unread,
Oct 28, 2012, 1:23:30 PM10/28/12
to puppet...@googlegroups.com
The definition doesn't need to be in its own module, but it should be in its own file within the module (which is what puppet-lint was telling you),

I know but having a definition which just copys files in a global name space would immensely reduce the amount of code duplication. I actually do not want to have the files definition in every module, I rather want to have my helper module which does that for me.

I hope you understood my intension of doing that.

Dan

Henrik Lindberg

unread,
Oct 29, 2012, 3:12:54 AM10/29/12
to puppet...@googlegroups.com
On 2012-25-10 22:33, danielt wrote:

> When I call the define from within my apache2 class with this:
>
> helper::files{$files:
> owner => root,
> group => root,
> mode => 644,
> path => "puppet:///files/apache2/",
> ensure => present,
> requires => File[$folders]
> }
>
Irrespective of other issues, you probably want to use the octal 0644
for mode. You currently have a decimal value 644 that corresponds to
01204 (octal) which is a quite different mode.

- henrik


jcbollinger

unread,
Oct 29, 2012, 2:22:23 PM10/29/12
to puppet...@googlegroups.com

That's not relevant to my answer.  Nevertheless, inasmuch as there is nothing special about defined types relative to built-in resources when it comes to arrays as resource titles, I'm not sure I agree that there is an immense amount of code duplication to be saved.  How is using an intermediary definition better than just writing this:

file { ${files}:
      ensure   => present,
      owner    => root,
      group    => root,
      mode     => 0644,
      source   => 'puppet:///files/apache2/',
      require  => File[$folders],
}

Note 1: "ensure => present" is likely not what you really want, but that's what your definition does.

Note 2: you might well not need that 'require' parameter, as Puppet will autorequire the parent directory of any managed file if the parent is itself managed.

Note 3: if it's the owner / group / mode that you don't want to duplicate, then you might want to consider the advantages of being explicit about what you want.  If you still want to avoid expressing those explicitly (and how many places are we talking about, really?) then you could consider setting global defaults for those parameters:

site.pp
-----------
# ...
File {

  owner => root,
  group => root,
  mode => 0644
}
# ...


John

Reply all
Reply to author
Forward
0 new messages