On Tuesday, January 5, 2016 at 11:01:57 AM UTC-6, linux script wrote:
>
> John,
>
> Sorry for the typos in the code.for some reason I had to type the code
> instead of copying.I thought it would give a general idea about the format
> in which I wanted to write it.
>
> Secondly, I used define inside a class because I could not see a way to
> call the define inside another class which is out of it.
>
> Let's say if I define something like *modules/profile/manifests/**user.pp*
> *:*
> define user (username=$name){
> }
>
That declaration is not what you want. Compare it to my example: you are
declaring a defined type named "user", but you put it in the file where
Puppet will look for one named "profile::user". Puppet uses class and
defined type names to find and load their definitions, but it does not use
filesystem paths to *assign* class or defined type names. You always get
exactly the name you declare. With the declaration you presented, in the
file you specified, Puppet will not be able to find defined type "user" (it
would look in file modules/user/manifests/init.pp, instead), and it will
not be able to find any defined type "profile::user" because you have not,
in fact, defined such a type.
> I want to call it into parms.pp where I assign all my variables related to
> this module something like below.$name should expand into actual user name
> which is passed through init.pp
>
> class profile::params {
> $bashrc_host = "modules/profile/$fqdn_$name_bashrc"
> $bashrc = '/home/$name/.bashrc'
> }
>
It seems unlikely to be a good design to declare defined-type instances in
a params class, but once you get the name and location sorted out you
certainly could do so. You should reference it by its full name, for
example
profile::user { 'user1': }
If you mean that you want profile::user instances to be able to access
variables from class profile::params, then it could hardly be simpler: you
can reference those variables from anywhere in your manifest set by means
of their qualified names. For example, $profile::params::bashrc.
The only caveat (and it applies everywhere), is that the definition of the
host class (profile::params) must have been evaluated before that access --
but not necessarily in the same scope as the variable reference. Because
classes are singletons, and especially for unparameterized classes such as
yours, it is safe to declare the same class multiple times via include-like
declarations. For Puppet 2.7, that means via either the 'include' function
or the 'require' function.
As such, it might be entirely reasonable and appropriate for the defined
type body to 'include' class profile::params:
define profile::user($param1, $param2) {
include '::profile::params'
# now assuredly safe to access $profile::params::bashrc, etc.
# ...
}
> I am using puppet 2.7.hence I cannot use iterations to make it happen.
>
>
Puppet 4's iteration features are convenient*, *but not essential. In any
event, I don't see how it makes a difference for this purpose whether they
are available or not. That is, I know you must be using an array title to
declare multiple defined type instances, but
1. myself, I'd strongly consider doing this particular job that way
anyway;
2. as I already said, data access does not depend on lexical scope; and
3. the central problem seems to revolve around how to create a defined
type, which is substantially the same in Puppet 4 as it was in Puppet 2.
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/bd9c3d49-144a-4b96-8d20-a65506e14a22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.