[Puppet Users] Re: defined types and enc

jcbollinger
Fri, 26 Oct 2012 19:24:52 -0000

On Friday, October 26, 2012 11:32:36 AM UTC-5, erkules
wrote:
>
>
> Moin,
> playing with puppet. I did some defined type creating
> lxc-application-containers.
> With that I could run a lot of virtualised applications on a host.
> I choose defined types to call them many times for a node.
> In my understanding classes will not be able to be called many times on a
> node.
> (''name-clashing'').
>


That''s sort-of true, but it misses the key point.  Classes represent
configurations features with singleton nature -- if managed at all then
they are either present/on or absent/off.  Thus, although there are ways to
declare the same class more than once, but they do not permit you to use
different sets of parameters, and they have no additional implications for
the target node''s configuration beyond what declaring that class once
would
have.

In any case, supposing that you want to be able to declare containers for
multiple different applications on the same node, you cannot model them all
via a single class (though you can model a particular collection of them
with a class).


>
> Trying to get my configuration into an enc. I looks like you can''t
use
> defined types via enc.
>
> So I wonder if Im wrong?
>


You are correct that an ENC cannot declare instances of a defined type, nor
of any other resource type for that matter.  It can declare only classes
and global variables.



> If not is there a trick to call a class many times for a node. (Maybe by
> manipulating the name?)
>
>
You can create classes with different names but similar content, or you can
use one class that wraps all the resources you want.  For example,

class mymodule::lxc_application_containers {
  mymodule::lxc_application_container { ''container1:
    application => ''Awesomeness1.1''
    # other parameters
  }
  mymodule::lxc_application_container { ''container2:
    application => ''Moneymaker3.2''
    # other parameters
  }
  # other containers ...
}

Supposing that the point is to select a subset of the available
applications for each target node, using the one-class approach, you can do
that via global variables (yuck), class parameters (meh), or data from an
external source (best bet).

On the other hand, don''t discard the idea of different classes too
lightly.  In many cases it makes a lot of sense.  In particular, it may
relieve pressure on your defined type to be sufficiently flexible to do
everything needed for any application you might ever want to use.  Having a
separate class for each module could make it a lot easier to deal with the
special needs of each application.

Note also that names in Puppet should not contain the hyphen (-).  It may
happen to work in some versions of Puppet, but it is not supported, and
some uses definitely will fail in various Puppet versions.  This applies
most to variable names, including parameter names, but also to class,
module, and definition names.


John

--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To view this discussion on the web visit