On Sat, Feb 18, 2012 at 9:43 PM, David <[email protected]> wrote:
> basefiles::conf { '/etc/passwd:' mode => 0644 }
> ...
> basefiles::conf { '/var/lib/otherfile:' mode => 0400 }
>
> .... and that's all groovy. The manifest looks concise and readable.
>
> But here's where I stare at a tree and get lost in the forrest: the manifest
> I'm writing contains my base list of files. On some of my machines, I will
> want to override that base and substitute a different copy of one or two
> files from that list (e.g. I will want a different /etc/passwd put in
> place).
>
> Further research leads me to this discussion of overriding defined resources
> and the futility of trying:
>
> https://groups.google.com/d/topic/puppet-users/SDa1F817UBA/discussion
>
> That discussion leads me to believe it isn't possible to override defined
> resources in the same way you might with a class. That makes me think I have
> to either:
>    a) move the files I might want to override out to their own separate
> class or
>    b) add some logic to the resource definition to do something magical for
> certain invocations

You can't override define definition, but you certainly can still
override define resources. So the first thing is you should do is to
have source as part of the parameter.

define basefiles::conf(
  $mode = '0644',
  $source = "puppet:///modules/${caller_module_name}/${name}"
){
  file { "${name}":
    source =>$source,
    mode   => $mode,
  }
}

Now you can certainly write a class that can be inherited and overritten:
class myfiles {
  basefiles::conf { '/etc/passwd': }
}

class myfiles::sub inherits myfiles {
  Basefiles::Conf['/etc/passwd'] {
    source => 'something new',
  }
}

But the following would probably be more flexible, either hard code a hierarchy:

define basefiles::conf(
  $mode = '0644',
  $source = ["puppet:///modules/${caller_module_name}/${hostname}/${name}",
                  "puppet:///modules/${caller_module_name}/${name}"]
){
  file { "${name}":
    source =>$source,
    mode   => $mode,
  }
}

Or just use hiera function (see our recent blog posts):

define basefiles::conf(
  $mode = '0644',
  $source = hiera($name, "puppet:///modules/${caller_module_name}/${name}")
){
  file { "${name}":
    source =>$source,
    mode   => $mode,
  }
}

HTH,

Nan

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to