On Wednesday, April 2, 2014 10:51:36 AM UTC-5, Thomas Hartmann wrote:
>
> Hi all,
>
> I am quite new to Puppet and are currently struggeling with the namespace.
>
> Thus, I have a manifest to deploy my service organized in
> manifests --> myservice.pp
>
> node "myservice.thing.foo"{
> class {'myservice::deploy':}
> }
>
> The module is located in
> modules --> myservice --> manifests --> deploy.pp
>
>
Ok, stop there.
1. Terminology: a Puppet module is a collection of sero or more classes,
definitions, files, templates, plugins, and data, using a common top-level
namespace and physically grouped together in a subdirectory of one of the
directories in your module path. A module is not "located in" a single
manifest file, even if there is only one manifest file belonging to that
module.
2. Terminology: Puppet classes are not modules.
3. Usage: your particular usage of the term "module" seems Pythonesque.
If you have that mindset or a similar one, then you must take care to shed
it when working on Puppet code. Specifically, in Python and some other
languages, files provide both physical and logical organization of your
code, whereas in Puppet they provide only physical organization. The main
practical implication is that you should have only one top-level
declaration in any manifest file other than your site manifest and any
other manifest logically included (e.g. via 'import') in your site manifest.
4. Organization: most Puppeteers would expect a manifest file named
"myservice.pp" to contain the definition of a class or definition named
[some_module::[inner_namespace::]]myservice. I guess a definition of a
node "myservice" works, too, but it is more common to organize single-node
node definition manifests under manifests/nodes/.
> class myservice::deploy()
> {
> ...dostuffhere...
> }
>
> So, now I would like to move some variables to a separate module, e.g.,
> modules --> myservice --> manifests --> subdir --> variablefoo.pp
>
> class variablefoo
> {
> $myvar1 = "HALLOWORLD"
> class variablebar
> {
> $myarr1 = [1,2,3]
> }
> }
>
Do not nest classes. It only confuses people.
Moreover, you define a class named 'variablefoo', but you put its manifest
where Puppet will look for a class named "myservice::subdir::variablefoo".
If you really want the class to be named "variablefoo" (and to be
recognized by the autoloader) then it should go in
modules/variablefoo/manifests/init.pp, where it would be the main class of
a module of the same name. Otherwise, you should define it with the
correct name.
> How can I access the elements in variablefoo.pp in my modules::deploy.pp,
> i.e., what is the complete namespace path??
>
The fully-qualified name of any variable is ${::classname::variablename}.
Often people use a mostly-qualified form instead:
${classname::variablename}. The curly braces are optional in many
contexts. The "classname" part is whatever you define the class's name to
be. In your example it is "variablefoo", but if you named the class so
that the autoloader could find it at its current location then its name
would need to be "myservice::subdir::variablefoo".
>
> I tried several pathes that seemed to be somewhat reasonable to me as
>
> $testvar = $subdir::variablefoo::myvar
> $testvar = myservice::subdir::variablefoo::myvar
>
> but apparently I have not really got into puppet yet :(
>
> Maybe, somebody can help me out?
>
>
I think you want to rename the class to "myservice::subdir::variablefoo",
and then refer to the variable as $myservice::subdir::variablefoo::myvar.
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/017aa5d0-c2f6-493c-842d-96154a1a2a30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.