Stefan Schulte
2011-Aug-06 14:14 UTC
[Puppet Users] Is accessing vars from different class safe?
Hi puppet users, I have a question about crossdependencies. Let''s say I want to manage an application my_application and the backupclient on a node. I always need a backclient but its configuration depends on a) wether my_application is installed or not b) the configuration of my_application This is one pattern I can think of: node ''mynode'' { class { ''my_application'': paramA => valueA, paramBalsoInterestingForBackupclass => valueB, paramCalsoInterestingForBackupclass => valueC, } class { ''backup::client'': backup_definitions => [ ''my_application'' ], } } Is it ALWAYS safe to access $::my_application::paramBalsoInterestingForBackup inside the backup::client class or can I run into ordering issues? Or how whould you model this kind of relationship? A second pattern I can think of is having a third class backup::client::my_application that takes the same params as the my_application class and gets included inside the my_application class. So I would end up with node ''mynode'' { class { ''my_application'': paramA => valueA, paramBalsoInterestingForBackupclass => valueB, paramCalsoInterestingForBackupcalss => valueC, backup => true, } class { ''backup::client'': } # just the basic config } and inside class my_application: if $backup { class { ''backup::client::my_application'': paramB => $paramBalsoInterestingForBackupclass, paramC => $paramCalsoInterestingForBackupclass, require => Class[''backup::client''], } } Does this sound like a better approach? Nevertheless is the first one save? -Stefan
John Martin
2011-Aug-06 23:27 UTC
[Puppet Users] Re: Is accessing vars from different class safe?
It doesn''t sound safe since it sounds like you don''t alway install the class. I would lean towards a configuratios class that you can reference to determine if it is or will be installed. I would pass in that value as a parameter to the backup class instead on internally referencing across classes as well. One last thing would be to use a "require config_class" statement before attempting to access the config var. John -- 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.
Stefan Schulte
2011-Aug-11 15:26 UTC
Re: [Puppet Users] Is accessing vars from different class safe?
On Sat, Aug 06, 2011 at 04:14:31PM +0200, Stefan Schulte wrote:> Is it ALWAYS safe to access $::my_application::paramBalsoInterestingForBackup > inside the backup::client class or can I run into ordering issues?At least I can answer this question my self: It is not safe, you can end up with 2 Modules with one class each class mod1::class1($message) { $messag = $message notice $message } class mod2::class2 { notice $mod1::class1::message } 1 Manifest class { ''mod2::class2'': } class { ''mod1::class1'': message => ''Hallo Welt''} Output warning: Scope(Class[Mod2::Class2]): Could not look up qualified variable ''mod1::class1::message''; class mod1::class1 has not been evaluated at /tmp/modules/mod2/manifests/class2.pp:2 notice: Scope(Class[Mod2::Class2]): notice: Scope(Class[Mod1::Class1]): Hallo Welt info: Applying configuration version ''1313075940'' notice: Finished catalog run in 0.16 seconds -Stefan
Aaron Grewell
2011-Aug-11 15:30 UTC
Re: [Puppet Users] Is accessing vars from different class safe?
It''s fine, just make sure class2 requires class1. That''s what requires are for. On Thu, Aug 11, 2011 at 8:26 AM, Stefan Schulte < stefan.schulte@taunusstein.net> wrote:> On Sat, Aug 06, 2011 at 04:14:31PM +0200, Stefan Schulte wrote: > > Is it ALWAYS safe to access > $::my_application::paramBalsoInterestingForBackup > > inside the backup::client class or can I run into ordering issues? > > At least I can answer this question my self: It is not safe, you can end > up with > > 2 Modules with one class each > > class mod1::class1($message) { > $messag = $message > notice $message > } > class mod2::class2 { > notice $mod1::class1::message > } > > 1 Manifest > > class { ''mod2::class2'': } > class { ''mod1::class1'': message => ''Hallo Welt''} > > Output > > warning: Scope(Class[Mod2::Class2]): Could not look up qualified > variable ''mod1::class1::message''; class mod1::class1 has not been > evaluated at /tmp/modules/mod2/manifests/class2.pp:2 > notice: Scope(Class[Mod2::Class2]): > notice: Scope(Class[Mod1::Class1]): Hallo Welt > info: Applying configuration version ''1313075940'' > notice: Finished catalog run in 0.16 seconds > > > -Stefan >-- 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.
Stefan Schulte
2011-Aug-11 15:54 UTC
Re: [Puppet Users] Is accessing vars from different class safe?
On Thu, Aug 11, 2011 at 08:30:37AM -0700, Aaron Grewell wrote:> It''s fine, just make sure class2 requires class1. That''s what requires are > for. >Unfortunately it still doesnt worked. Changed class2 to class mod2::class2 { file { $mod1::class1::message: ensure => file, require => Class[''mod1::class1''], } } Manifest is still class { ''mod2::class2'': } class { ''mod1::class1'': message => ''Hallo Welt''} What I get is warning: Scope(Class[Mod2::Class2]): Could not look up qualified variable ''mod1::class1::message''; class mod1::class1 has not been evaluated at /tmp/modules/mod2/manifests/class2.pp:2 notice: Scope(Class[Mod1::Class1]): Hallo Welt Parameter path failed: File paths must be fully qualified, not ''undef'' at /tmp/modules/mod2/manifests/class2.pp:5 If I change the order in the manifest it works. -Stefan> On Thu, Aug 11, 2011 at 8:26 AM, Stefan Schulte < > stefan.schulte@taunusstein.net> wrote: > > > On Sat, Aug 06, 2011 at 04:14:31PM +0200, Stefan Schulte wrote: > > > Is it ALWAYS safe to access > > $::my_application::paramBalsoInterestingForBackup > > > inside the backup::client class or can I run into ordering issues? > > > > At least I can answer this question my self: It is not safe, you can end > > up with > > > > 2 Modules with one class each > > > > class mod1::class1($message) { > > $messag = $message > > notice $message > > } > > class mod2::class2 { > > notice $mod1::class1::message > > } > > > > 1 Manifest > > > > class { ''mod2::class2'': } > > class { ''mod1::class1'': message => ''Hallo Welt''} > > > > Output > > > > warning: Scope(Class[Mod2::Class2]): Could not look up qualified > > variable ''mod1::class1::message''; class mod1::class1 has not been > > evaluated at /tmp/modules/mod2/manifests/class2.pp:2 > > notice: Scope(Class[Mod2::Class2]): > > notice: Scope(Class[Mod1::Class1]): Hallo Welt > > info: Applying configuration version ''1313075940'' > > notice: Finished catalog run in 0.16 seconds > > > > > > -Stefan > > > > -- > 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. >
Aaron Grewell
2011-Aug-11 16:23 UTC
Re: [Puppet Users] Is accessing vars from different class safe?
I think you''ll have to do it at the class level with the arrow operators rather than at the resource level. I haven''t ever done that, but I think if the manifest contains something like: class { ''mod2::class2'': } class { ''mod1::class1'': message => ''Hallo Welt''} mod1 -> mod2 you may have better luck. On Thu, Aug 11, 2011 at 8:54 AM, Stefan Schulte < stefan.schulte@taunusstein.net> wrote:> On Thu, Aug 11, 2011 at 08:30:37AM -0700, Aaron Grewell wrote: > > It''s fine, just make sure class2 requires class1. That''s what requires > are > > for. > > > > Unfortunately it still doesnt worked. Changed class2 to > > class mod2::class2 { > file { $mod1::class1::message: > ensure => file, > require => Class[''mod1::class1''], > } > } > > Manifest is still > > class { ''mod2::class2'': } > class { ''mod1::class1'': message => ''Hallo Welt''} > > What I get is > > warning: Scope(Class[Mod2::Class2]): Could not look up qualified > variable ''mod1::class1::message''; class mod1::class1 has not been > evaluated at /tmp/modules/mod2/manifests/class2.pp:2 > > notice: Scope(Class[Mod1::Class1]): Hallo Welt > > Parameter path failed: File paths must be fully qualified, not ''undef'' > at /tmp/modules/mod2/manifests/class2.pp:5 > > If I change the order in the manifest it works. > > -Stefan > > On Thu, Aug 11, 2011 at 8:26 AM, Stefan Schulte < > > stefan.schulte@taunusstein.net> wrote: > > > > > On Sat, Aug 06, 2011 at 04:14:31PM +0200, Stefan Schulte wrote: > > > > Is it ALWAYS safe to access > > > $::my_application::paramBalsoInterestingForBackup > > > > inside the backup::client class or can I run into ordering issues? > > > > > > At least I can answer this question my self: It is not safe, you can > end > > > up with > > > > > > 2 Modules with one class each > > > > > > class mod1::class1($message) { > > > $messag = $message > > > notice $message > > > } > > > class mod2::class2 { > > > notice $mod1::class1::message > > > } > > > > > > 1 Manifest > > > > > > class { ''mod2::class2'': } > > > class { ''mod1::class1'': message => ''Hallo Welt''} > > > > > > Output > > > > > > warning: Scope(Class[Mod2::Class2]): Could not look up qualified > > > variable ''mod1::class1::message''; class mod1::class1 has not been > > > evaluated at /tmp/modules/mod2/manifests/class2.pp:2 > > > notice: Scope(Class[Mod2::Class2]): > > > notice: Scope(Class[Mod1::Class1]): Hallo Welt > > > info: Applying configuration version ''1313075940'' > > > notice: Finished catalog run in 0.16 seconds > > > > > > > > > -Stefan > > > > > > > -- > > 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.
Stefan Schulte
2011-Aug-11 16:55 UTC
Re: [Puppet Users] Is accessing vars from different class safe?
On Thu, Aug 11, 2011 at 09:23:51AM -0700, Aaron Grewell wrote:> I think you''ll have to do it at the class level with the arrow operators > rather than at the resource level. I haven''t ever done that, but I think if > the manifest contains something like: > > class { ''mod2::class2'': } > class { ''mod1::class1'': message => ''Hallo Welt''} > mod1 -> mod2 > > you may have better luck.Nope. Neither does class { ''mod2::class2'': require => Class[''mod1::class1'']} class { ''mod1::class1'': message => ''Hallo Welt''} nor does class { ''mod2::class2'': require => Class[''mod2::class2'']} class { ''mod1::class1'': message => ''Hallo Welt''} Class[''mod1::class1''] -> Class[''mod2::class2''] work. So you basically run into the same issues as when you use the defined function to check for other classes inside a class: It all depends on the parsing order. At least I get a warning if the order in my manifest is wrong: warning: Scope(Class[Mod2::Class2]): Could not look up qualified variable ''mod1::class1::message''; class mod1::class1 has not been evaluated at /tmp/modules/mod2/manifests/class2.pp:2 but unfortunately puppet does not fail hard here but just applies a catalog with some empty variables which in my opinion is just wrong. -Stefan
jcbollinger
2011-Aug-11 21:30 UTC
[Puppet Users] Re: Is accessing vars from different class safe?
On Aug 11, 10:54 am, Stefan Schulte <stefan.schu...@taunusstein.net> wrote:> On Thu, Aug 11, 2011 at 08:30:37AM -0700, Aaron Grewell wrote: > > It''s fine, just make sure class2 requires class1. That''s what requires are > > for. > > Unfortunately it still doesnt worked. Changed class2 to > > class mod2::class2 { > file { $mod1::class1::message: > ensure => file, > require => Class[''mod1::class1''], > } > } > > Manifest is still > > class { ''mod2::class2'': } > class { ''mod1::class1'': message => ''Hallo Welt''} > > What I get is > > warning: Scope(Class[Mod2::Class2]): Could not look up qualified > variable ''mod1::class1::message''; class mod1::class1 has not been > evaluated at /tmp/modules/mod2/manifests/class2.pp:2I must say I''m not surprised that one didn''t work. Indeed, I would have been surprised if it had. The require is inside a scope defined by the variable in question, and that scope can''t be defined in the first place. I think I know what''s going on. Basically, ''require'' and its friends are the the wrong tool for the job: they establish order relationships for determining the order in which resources are *applied* by the agent, but they not necessarily the order in which resources are evaluated during catalog compilation by the master. Were class1 not parameterized, I would recommend that class2 simply ''include'' it, and I am confident that would make it all good. But you cannot do that with a parameterized class (as far as I am aware), so I think that leaves you up a creek. John Parameterized Classes -- Finding new ways to break your manifests since 2010! -- 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.
Aaron Grewell
2011-Aug-11 22:05 UTC
Re: [Puppet Users] Re: Is accessing vars from different class safe?
Thanks John , I wasn''t aware of that distinction. I suspect you''ve saved me a forehead=>wall session on down the road. :-) On Aug 11, 2011 2:31 PM, "jcbollinger" <John.Bollinger@stjude.org> wrote:> > > On Aug 11, 10:54 am, Stefan Schulte <stefan.schu...@taunusstein.net> > wrote: >> On Thu, Aug 11, 2011 at 08:30:37AM -0700, Aaron Grewell wrote: >> > It''s fine, just make sure class2 requires class1. That''s what requiresare>> > for. >> >> Unfortunately it still doesnt worked. Changed class2 to >> >> class mod2::class2 { >> file { $mod1::class1::message: >> ensure => file, >> require => Class[''mod1::class1''], >> } >> } >> >> Manifest is still >> >> class { ''mod2::class2'': } >> class { ''mod1::class1'': message => ''Hallo Welt''} >> >> What I get is >> >> warning: Scope(Class[Mod2::Class2]): Could not look up qualified >> variable ''mod1::class1::message''; class mod1::class1 has not been >> evaluated at /tmp/modules/mod2/manifests/class2.pp:2 > > > I must say I''m not surprised that one didn''t work. Indeed, I would > have been surprised if it had. The require is inside a scope defined > by the variable in question, and that scope can''t be defined in the > first place. > > I think I know what''s going on. Basically, ''require'' and its friends > are the the wrong tool for the job: they establish order relationships > for determining the order in which resources are *applied* by the > agent, but they not necessarily the order in which resources are > evaluated during catalog compilation by the master. > > Were class1 not parameterized, I would recommend that class2 simply > ''include'' it, and I am confident that would make it all good. But you > cannot do that with a parameterized class (as far as I am aware), so I > think that leaves you up a creek. > > > John > Parameterized Classes -- Finding new ways to break your manifests > since 2010! > > -- > 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 topuppet-users+unsubscribe@googlegroups.com.> For more options, visit this group athttp://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.