Hi everybody! I would like to share a group of variables between definitions and I don''t know what it is the best approach to do this... First, let me explain the situation... I were using a class and defining those variables inside of it.. then I used inheritance to this class to get the variables instantiated. For instance: class common_variables { $a_var = "hello world" } class class_a inherits common_variables { notice($a_var) } class class_b inherits common_variables { notice($a_var) } The problem, is since class are singletons, I can''t do that in a situation where need to have multiple instances of class_a and class_b on in a host. So, I am trying to implement the same logic using definitions, but after reading the language tutorial at puppet''s official wiki, I still haven''t found a nice way to do. One solution would be to put the definition of $a_var inside boths defines, but I didn''t like to do that. Has anyone experienced a problem like this? what would it be the best approach and the "right" way to do it? Thanks in advance, Gus -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael DeHaan
2010-Mar-24 21:11 UTC
Re: [Puppet Users] sharing variables between definitions
On Wed, Mar 24, 2010 at 3:10 PM, Gustavo Soares <gustavosoares@gmail.com>wrote:> Hi everybody! > > I would like to share a group of variables between definitions and I don''t > know what it is the best approach to do this... > > First, let me explain the situation... > > I were using a class and defining those variables inside of it.. then I > used inheritance to this class to > get the variables instantiated. > > For instance: > > class common_variables { > $a_var = "hello world" > } > > class class_a inherits common_variables { > notice($a_var) > } > > class class_b inherits common_variables { > notice($a_var) > } >If I understand this correctly, you''d like to use different variables with the same definitions? This sends "5" as a notice value: class base { $x=3 define yell($what) { notice($what) } } class outera inherits base { $x=4 base::yell { "some title" : what => $x } } class outerb inherits base { $x=5 base::yell { "some title" : what => $x } } Let me know if I misunderstood. --Michael -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael DeHaan
2010-Mar-24 21:22 UTC
Re: [Puppet Users] sharing variables between definitions
On Wed, Mar 24, 2010 at 5:11 PM, Michael DeHaan <michael@reductivelabs.com>wrote:> > On Wed, Mar 24, 2010 at 3:10 PM, Gustavo Soares <gustavosoares@gmail.com>wrote: > >> Hi everybody! >> >> I would like to share a group of variables between definitions and I don''t >> know what it is the best approach to do this... >> >> First, let me explain the situation... >> >> I were using a class and defining those variables inside of it.. then I >> used inheritance to this class to >> get the variables instantiated. >> >> For instance: >> >> class common_variables { >> $a_var = "hello world" >> } >> >> class class_a inherits common_variables { >> notice($a_var) >> } >> >> class class_b inherits common_variables { >> notice($a_var) >> } >> > > > If I understand this correctly, you''d like to use different variables with > the same definitions? > > This sends "5" as a notice value: > > class base { > $x=3 > define yell($what) { > notice($what) > } > } > > class outera inherits base { > $x=4 > base::yell { "some title" : what => $x } > } > > class outerb inherits base { > $x=5 > base::yell { "some title" : what => $x } > } > > >Sorry for the confusion -- I''m missing a "include base" at the very bottom of my example. If that''s not what you meant about variables in defines, please clarify.>-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Gustavo Soares
2010-Mar-24 21:51 UTC
Re: [Puppet Users] sharing variables between definitions
Hi, Michael! thanks for your reply! actually it is the opposite.. :) i.e, I want to use the same variable, but in different definitions... Using classes, I can accomplish that using class inheritance, but with definitions.. I have no clue... Just to clarify the reason of that... 1) I have a couple of common variables 2) I have a define A 2) I have a define B I need to have multiple instances of objects defined in define A in one host and multiple instances of objects defined in define B on another host, but both define (A and B) share a couple of variables... Using classes this is pretty straight forward, but since classes are singleton, I need to use Definitions and I don''t know how to do that without putting the "shared variables" in each definition. I hope, I have managed to clarify the issue. Cheers, Gus On Wed, Mar 24, 2010 at 6:22 PM, Michael DeHaan <michael@reductivelabs.com>wrote:> > > On Wed, Mar 24, 2010 at 5:11 PM, Michael DeHaan <michael@reductivelabs.com > > wrote: > >> >> On Wed, Mar 24, 2010 at 3:10 PM, Gustavo Soares <gustavosoares@gmail.com>wrote: >> >>> Hi everybody! >>> >>> I would like to share a group of variables between definitions and I >>> don''t know what it is the best approach to do this... >>> >>> First, let me explain the situation... >>> >>> I were using a class and defining those variables inside of it.. then I >>> used inheritance to this class to >>> get the variables instantiated. >>> >>> For instance: >>> >>> class common_variables { >>> $a_var = "hello world" >>> } >>> >>> class class_a inherits common_variables { >>> notice($a_var) >>> } >>> >>> class class_b inherits common_variables { >>> notice($a_var) >>> } >>> >> >> >> If I understand this correctly, you''d like to use different variables with >> the same definitions? >> >> This sends "5" as a notice value: >> >> class base { >> $x=3 >> define yell($what) { >> notice($what) >> } >> } >> >> class outera inherits base { >> $x=4 >> base::yell { "some title" : what => $x } >> } >> >> class outerb inherits base { >> $x=5 >> base::yell { "some title" : what => $x } >> } >> >> >> > Sorry for the confusion -- > > I''m missing a "include base" at the very bottom of my example. > > If that''s not what you meant about variables in defines, please clarify. > > > >> > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael DeHaan
2010-Mar-24 22:15 UTC
Re: [Puppet Users] sharing variables between definitions
On Wed, Mar 24, 2010 at 5:51 PM, Gustavo Soares <gustavosoares@gmail.com>wrote:> Hi, Michael! thanks for your reply! > > actually it is the opposite.. :) i.e, I want to use the same variable, but > in different definitions... >Ok, sorry for the confusion. I would have thought "$common_variables::x" would have worked to reference something in a parent, but it does not. Perhaps someone else can share a workaround as I''m not too familiar with scoping in this case. I know you can do variables at top scope or through your external nodes classifier, but that is not ideal. --Michael -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael Gliwinski
2010-Mar-25 09:43 UTC
Re: [Puppet Users] sharing variables between definitions
On Wednesday 24 Mar 2010 22:15:27 Michael DeHaan wrote:> On Wed, Mar 24, 2010 at 5:51 PM, Gustavo Soares<gustavosoares@gmail.com>wrote:> > Hi, Michael! thanks for your reply! > > > > actually it is the opposite.. :) i.e, I want to use the same variable, > > but in different definitions... > > Ok, sorry for the confusion. > > I would have thought "$common_variables::x" would have worked to reference > something in a parent, but it does not. > > Perhaps someone else can share a workaround as I''m not too familiar with > scoping in this case. > > I know you can do variables at top scope or through your external nodes > classifier, but that is not ideal. > > --Michael >IIRC you also need to ''include'' the class within the define, then qualified variables (like ${class::variable}) should work. YMMV, these kinds of things have always caused enough issues to drive me crazy, but definitely possible. -- Michael Gliwinski Henderson Group Information Services 9-11 Hightown Avenue, Newtownabby, BT36 4RT Phone: 028 9034 3319 ********************************************************************************************** The information in this email is confidential and may be legally privileged. It is intended solely for the addressee and access to the email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. When addressed to our clients, any opinions or advice contained in this e-mail are subject to the terms and conditions expressed in the governing client engagement leter or contract. If you have received this email in error please notify support@henderson-group.com John Henderson (Holdings) Ltd Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern Ireland, BT36 4RT. Registered in Northern Ireland Registration Number NI010588 Vat No.: 814 6399 12 ********************************************************************************* -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Gustavo Soares
2010-Mar-25 11:48 UTC
Re: [Puppet Users] sharing variables between definitions
I have thought of using qualified variables, but i think that won''t work inside a tempalte, right? Or can I do <%= class::variable %> ? And I guess that if I am using dynamic variables, once I include the it will be evaluated only once, right? Gus ------- Original message -------> From: Michael Gliwinski <Michael.Gliwinski@henderson-group.com> > To: puppet-users@googlegroups.com > Sent: 25.3.''10, 6:46 > > On Wednesday 24 Mar 2010 22:15:27 Michael DeHaan wrote: >> On Wed, Mar 24, 2010 at 5:51 PM, Gustavo Soares > <gustavosoares@gmail.com>wrote: >> > Hi, Michael! thanks for your reply! >> > >> > actually it is the opposite.. :) i.e, I want to use the same variable, >> > but in different definitions... >> >> Ok, sorry for the confusion. >> >> I would have thought "$common_variables::x" would have worked to >> reference >> something in a parent, but it does not. >> >> Perhaps someone else can share a workaround as I''m not too familiar with >> scoping in this case. >> >> I know you can do variables at top scope or through your external nodes >> classifier, but that is not ideal. >> >> --Michael >> > > IIRC you also need to ''include'' the class within the define, then > qualified > variables (like ${class::variable}) should work. YMMV, these kinds of > things > have always caused enough issues to drive me crazy, but definitely > possible. > > > -- > Michael Gliwinski > Henderson Group Information Services > 9-11 Hightown Avenue, Newtownabby, BT36 4RT > Phone: 028 9034 3319 > > > *************************************************************************** > ******************* > The information in this email is confidential and may be legally > privileged. It is intended solely for the addressee and access to the > email by anyone else is unauthorised. > If you are not the intended recipient, any disclosure, copying, > distribution or any action taken or omitted to be taken in reliance on it, > is prohibited and may be unlawful. > When addressed to our clients, any opinions or advice contained in this > e-mail are subject to the terms and conditions expressed in the governing > client engagement leter or contract. > If you have received this email in error please notify > support@henderson-group.com > > John Henderson (Holdings) Ltd > Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern > Ireland, BT36 4RT. > Registered in Northern Ireland > Registration Number NI010588 > Vat No.: 814 6399 12 > > *************************************************************************** > ****** > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael Gliwinski
2010-Mar-25 12:54 UTC
Re: [Puppet Users] sharing variables between definitions
On Thursday 25 Mar 2010 11:48:44 Gustavo Soares wrote:> I have thought of using qualified variables, but i think that won''t work > inside a tempalte, right? Or can I do <%= class::variable %> ?It will but you have to use <%= scope.lookup(''class::variable'') %> (note, typing from memory, to be sure check the puppet templating page on the wiki, there is an example there).> And I guess that if I am using dynamic variables, once I include the it > will be evaluated only once, right?I''m not sure what you mean by dynamic variables, but the class is indeed evaluated only once (and therefore variables are bound only once IIUC), even though it is included from a define which may be declared (i.e. ''called''?) multiple times. -- Michael Gliwinski Henderson Group Information Services 9-11 Hightown Avenue, Newtownabby, BT36 4RT Phone: 028 9034 3319 ********************************************************************************************** The information in this email is confidential and may be legally privileged. It is intended solely for the addressee and access to the email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. When addressed to our clients, any opinions or advice contained in this e-mail are subject to the terms and conditions expressed in the governing client engagement leter or contract. If you have received this email in error please notify support@henderson-group.com John Henderson (Holdings) Ltd Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern Ireland, BT36 4RT. Registered in Northern Ireland Registration Number NI010588 Vat No.: 814 6399 12 ********************************************************************************* -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Gustavo Soares
2010-Mar-25 13:42 UTC
Re: [Puppet Users] sharing variables between definitions
Hi, Michael, thank you for your reply. What I mean about "dynamic variables" is: let''s say that I have a variable like *$log_path = "/var/log/$site" *to specify the log path for different applications that run on the same host. Thus, depending on the value of $site variable, the $log_path variable will be different. If I put that in a class, it will be evaluated for the first value of $site called, right? or am I missing something? I hope, that I could clarify. :) Gus On Thu, Mar 25, 2010 at 9:54 AM, Michael Gliwinski < Michael.Gliwinski@henderson-group.com> wrote:> On Thursday 25 Mar 2010 11:48:44 Gustavo Soares wrote: > > I have thought of using qualified variables, but i think that won''t work > > inside a tempalte, right? Or can I do <%= class::variable %> ? > > It will but you have to use <%= scope.lookup(''class::variable'') %> (note, > typing from memory, to be sure check the puppet templating page on the > wiki, > there is an example there). > > > And I guess that if I am using dynamic variables, once I include the it > > will be evaluated only once, right? > > I''m not sure what you mean by dynamic variables, but the class is indeed > evaluated only once (and therefore variables are bound only once IIUC), > even > though it is included from a define which may be declared (i.e. ''called''?) > multiple times. > > > -- > Michael Gliwinski > Henderson Group Information Services > 9-11 Hightown Avenue, Newtownabby, BT36 4RT > Phone: 028 9034 3319 > > > ********************************************************************************************** > The information in this email is confidential and may be legally > privileged. It is intended solely for the addressee and access to the email > by anyone else is unauthorised. > If you are not the intended recipient, any disclosure, copying, > distribution or any action taken or omitted to be taken in reliance on it, > is prohibited and may be unlawful. > When addressed to our clients, any opinions or advice contained in this > e-mail are subject to the terms and conditions expressed in the governing > client engagement leter or contract. > If you have received this email in error please notify > support@henderson-group.com > > John Henderson (Holdings) Ltd > Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern > Ireland, BT36 4RT. > Registered in Northern Ireland > Registration Number NI010588 > Vat No.: 814 6399 12 > > ********************************************************************************* > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Gustavo Soares
2010-Mar-25 14:21 UTC
Re: [Puppet Users] sharing variables between definitions
well, forget what I said.. It seems that I have misunderstood the variable scope... I will try to do as you suggest. Thanks! On Thu, Mar 25, 2010 at 10:42 AM, Gustavo Soares <gustavosoares@gmail.com>wrote:> Hi, Michael, thank you for your reply. > > What I mean about "dynamic variables" is: > > let''s say that I have a variable like *$log_path = "/var/log/$site" *to > specify the log path for different applications > that run on the same host. Thus, depending on the value of $site > variable, the $log_path variable will be different. > > If I put that in a class, it will be evaluated for the first value of $site > called, right? or am I missing something? > > I hope, that I could clarify. :) > > Gus > > On Thu, Mar 25, 2010 at 9:54 AM, Michael Gliwinski < > Michael.Gliwinski@henderson-group.com> wrote: > >> On Thursday 25 Mar 2010 11:48:44 Gustavo Soares wrote: >> > I have thought of using qualified variables, but i think that won''t work >> > inside a tempalte, right? Or can I do <%= class::variable %> ? >> >> It will but you have to use <%= scope.lookup(''class::variable'') %> (note, >> typing from memory, to be sure check the puppet templating page on the >> wiki, >> there is an example there). >> >> > And I guess that if I am using dynamic variables, once I include the it >> > will be evaluated only once, right? >> >> I''m not sure what you mean by dynamic variables, but the class is indeed >> evaluated only once (and therefore variables are bound only once IIUC), >> even >> though it is included from a define which may be declared (i.e. ''called''?) >> multiple times. >> >> >> -- >> Michael Gliwinski >> Henderson Group Information Services >> 9-11 Hightown Avenue, Newtownabby, BT36 4RT >> Phone: 028 9034 3319 >> >> >> ********************************************************************************************** >> The information in this email is confidential and may be legally >> privileged. It is intended solely for the addressee and access to the email >> by anyone else is unauthorised. >> If you are not the intended recipient, any disclosure, copying, >> distribution or any action taken or omitted to be taken in reliance on it, >> is prohibited and may be unlawful. >> When addressed to our clients, any opinions or advice contained in this >> e-mail are subject to the terms and conditions expressed in the governing >> client engagement leter or contract. >> If you have received this email in error please notify >> support@henderson-group.com >> >> John Henderson (Holdings) Ltd >> Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern >> Ireland, BT36 4RT. >> Registered in Northern Ireland >> Registration Number NI010588 >> Vat No.: 814 6399 12 >> >> ********************************************************************************* >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Puppet Users" group. >> To post to this group, send email to puppet-users@googlegroups.com. >> To unsubscribe from this group, send email to >> puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/puppet-users?hl=en. >> >> >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael Gliwinski
2010-Mar-25 14:23 UTC
Re: [Puppet Users] sharing variables between definitions
Ah, yes, in this case putting it in a class wouldn''t work. Well, obviously it wouldn''t apply to all variables but in case of paths what I often to is split it, e.g. have $log_root = "/var/log" in the class and in the define do ${class::log_root}/${site}. On Thursday 25 Mar 2010 13:42:13 Gustavo Soares wrote:> Hi, Michael, thank you for your reply. > > What I mean about "dynamic variables" is: > > let''s say that I have a variable like *$log_path = "/var/log/$site" *to > specify the log path for different applications > that run on the same host. Thus, depending on the value of $site > variable, the $log_path variable will be different. > > If I put that in a class, it will be evaluated for the first value of $site > called, right? or am I missing something? > > I hope, that I could clarify. :) > > Gus > > On Thu, Mar 25, 2010 at 9:54 AM, Michael Gliwinski < > > Michael.Gliwinski@henderson-group.com> wrote: > > On Thursday 25 Mar 2010 11:48:44 Gustavo Soares wrote: > > > I have thought of using qualified variables, but i think that won''t > > > work inside a tempalte, right? Or can I do <%= class::variable %> ? > > > > It will but you have to use <%= scope.lookup(''class::variable'') %> (note, > > typing from memory, to be sure check the puppet templating page on the > > wiki, > > there is an example there). > > > > > And I guess that if I am using dynamic variables, once I include the it > > > will be evaluated only once, right? > > > > I''m not sure what you mean by dynamic variables, but the class is indeed > > evaluated only once (and therefore variables are bound only once IIUC), > > even > > though it is included from a define which may be declared (i.e. > > ''called''?) multiple times. > > > > > > -- > > Michael Gliwinski > > Henderson Group Information Services > > 9-11 Hightown Avenue, Newtownabby, BT36 4RT > > Phone: 028 9034 3319 > > > > > > ************************************************************************* > >********************* The information in this email is confidential and > > may be legally privileged. It is intended solely for the addressee and > > access to the email by anyone else is unauthorised. > > If you are not the intended recipient, any disclosure, copying, > > distribution or any action taken or omitted to be taken in reliance on > > it, is prohibited and may be unlawful. > > When addressed to our clients, any opinions or advice contained in this > > e-mail are subject to the terms and conditions expressed in the > > governing client engagement leter or contract. > > If you have received this email in error please notify > > support@henderson-group.com > > > > John Henderson (Holdings) Ltd > > Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern > > Ireland, BT36 4RT. > > Registered in Northern Ireland > > Registration Number NI010588 > > Vat No.: 814 6399 12 > > > > ************************************************************************* > >******** > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@goog > >legroups.com> . > > For more options, visit this group at > > http://groups.google.com/group/puppet-users?hl=en. >-- Michael Gliwinski Henderson Group Information Services 9-11 Hightown Avenue, Newtownabby, BT36 4RT Phone: 028 9034 3319 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.