On Fri, Mar 04, 2011 at 01:46:54PM -0500, Trevor Vaughan wrote:
> Is it possible to create a composite namevar when creating a custom type?
> 
> Say you have an /etc/passwd like file that could exist at multiple locations.
> 
> The actual unique set of variables is the target path of the file
> combined with the username.
> 
> I'm trying to avoid something like:
> 
> foo { "/some/crazy/path:username": ..... }
> 
> Any suggestions?
> 
> Thanks,
> 
> Trevor
> 
> -- 

Yes it is possible to have a composite namevar. But there are a few bugs
in the current codebase that I noticed while writing a type to handle
entries in /etc/services (you can have telnet/udp and telnet/tcp for
example). They are documented in http://projects.puppetlabs.com/issues/5660

The title however has to be unique because you need a way to reference
a resource when declaring dependencies. But the title can implicitly set
multiple namevars. So

  foo { "/some/crazy/path:username": ...}

can set path to "/some/crazy/path" and username to "username". All you
need to do here is

a) use isnamevar multiple times
b) define a classmethod called title_patterns that can split the title
   in multiple namevars

example:
https://github.com/stschulte/puppet/blob/54ab7f7268fb9d39626057e6e023683ee5ae3f66/lib/puppet/type/port.rb

-Stefan

Attachment: pgpudPhSRekvV.pgp
Description: PGP signature

Reply via email to