Thomas Rasmussen
2011-Aug-05 07:02 UTC
[Puppet Users] Variable scope when having node inheritance
Hi I''m having some trouble with the following setup: node ''serverA'' inherits server-defaults { include myApp::install } node ''server-defaults'' inherits default { $sudoenv = ''custom_server'' } node default { $sudoenv = ''default'' include sudoers::config } class sudoers::config { file { "/etc/sudoers": ensure => file, owner => "root", group => "root", mode => 440, source => "puppet:///modules/sudoers/sudoers_ $sudoenv", } } I have then created to files: sudoers_default and sudoers_custom_server I want to have a default sudoers file on most of my servers, but on a few others, I need a different one, but on serverA I only get the sudoers_default file. I have tried to create it as a template (still using the $sudoenv varialbe) but this does not have any effect. Only if I move the include sudoers::config to the ''server-defaults'' node, then it works as I want. Being somewhat new to puppet, I really cant figure out how I can solve this task, but hopefully somebody can give some good hints? There isn''t any of my default variables that I can use instead of $sudoenv. Hope somebody has hints Regards Thomas -- 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.
Denmat
2011-Aug-05 08:09 UTC
Re: [Puppet Users] Variable scope when having node inheritance
Hi, You setting sudoenv to default in the default node. That is not overridden by subsequent node declarations. If you are using 2.6 and above I would pass a parameter to the sudoers class.> class sudoers::config (env = ''default'') { > file { "/etc/sudoers": > ensure => file, > owner => "root", > group => "root", > mode => 440, > source => "puppet:///modules/sudoers/sudoers_ > ${env}", > }then maybe call like this.> node ''server-defaults'' inherits default { > class {"sudoers::config": env => ''custom_server'' } > }then> node default { > class {"sudoers::config": } > }That might help you. Cheers, Den On 05/08/2011, at 17:02, Thomas Rasmussen <rasmussen.thomas@gmail.com> wrote:> Hi > > I''m having some trouble with the following setup: > > node ''serverA'' inherits server-defaults { > include myApp::install > } > > node ''server-defaults'' inherits default { > $sudoenv = ''custom_server'' > } > > node default { > $sudoenv = ''default'' > include sudoers::config > } > > class sudoers::config { > file { "/etc/sudoers": > ensure => file, > owner => "root", > group => "root", > mode => 440, > source => "puppet:///modules/sudoers/sudoers_ > $sudoenv", > } > } > > I have then created to files: sudoers_default and > sudoers_custom_server > > I want to have a default sudoers file on most of my servers, but on a > few others, I need a different one, but on serverA I only get the > sudoers_default file. I have tried to create it as a template (still > using the $sudoenv varialbe) but this does not have any effect. Only > if I move the include sudoers::config to the ''server-defaults'' node, > then it works as I want. > > Being somewhat new to puppet, I really cant figure out how I can solve > this task, but hopefully somebody can give some good hints? > > There isn''t any of my default variables that I can use instead of > $sudoenv. > > Hope somebody has hints > > Regards > Thomas > > -- > 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.
Thomas Rasmussen
2011-Aug-05 08:25 UTC
[Puppet Users] Re: Variable scope when having node inheritance
Hi Thanks for the reply, that works, but I''d like to keep my include of the sudoers::config in my default node section, but if I do that, then I don''t have the $sudoenv variable available at that time. Is there any way of overriding a previously include of a class? I tried to ''sudoers::config'': sudoenv=> $sudoenv, stage => install; in my server-defaults node definition, but puppet gave me a duplicate error on include. I''m running 2.6.4 on both server and client side. Regards Thomas On Aug 5, 10:09 am, Denmat <tu2bg...@gmail.com> wrote:> Hi, > > You setting sudoenv to default in the default node. That is not overridden by subsequent node declarations. > > If you are using 2.6 and above I would pass a parameter to the sudoers class. > > > class sudoers::config (env = ''default'') { > > file { "/etc/sudoers": > > ensure => file, > > owner => "root", > > group => "root", > > mode => 440, > > source => "puppet:///modules/sudoers/sudoers_ > > ${env}", > > } > > then maybe call like this. > > > node ''server-defaults'' inherits default { > > class {"sudoers::config": env => ''custom_server'' } > > } > > then > > > node default { > > class {"sudoers::config": } > > } > > That might help you. > > Cheers, > Den > On 05/08/2011, at 17:02, Thomas Rasmussen <rasmussen.tho...@gmail.com> wrote: > > > > > > > > > Hi > > > I''m having some trouble with the following setup: > > > node ''serverA'' inherits server-defaults { > > include myApp::install > > } > > > node ''server-defaults'' inherits default { > > $sudoenv = ''custom_server'' > > } > > > node default { > > $sudoenv = ''default'' > > include sudoers::config > > } > > > class sudoers::config { > > file { "/etc/sudoers": > > ensure => file, > > owner => "root", > > group => "root", > > mode => 440, > > source => "puppet:///modules/sudoers/sudoers_ > > $sudoenv", > > } > > } > > > I have then created to files: sudoers_default and > > sudoers_custom_server > > > I want to have a default sudoers file on most of my servers, but on a > > few others, I need a different one, but on serverA I only get the > > sudoers_default file. I have tried to create it as a template (still > > using the $sudoenv varialbe) but this does not have any effect. Only > > if I move the include sudoers::config to the ''server-defaults'' node, > > then it works as I want. > > > Being somewhat new to puppet, I really cant figure out how I can solve > > this task, but hopefully somebody can give some good hints? > > > There isn''t any of my default variables that I can use instead of > > $sudoenv. > > > Hope somebody has hints > > > Regards > > Thomas > > > -- > > 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 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.
Denmat
2011-Aug-05 10:00 UTC
Re: [Puppet Users] Re: Variable scope when having node inheritance
This might shed some more light for you: http://docs.puppetlabs.com/guides/troubleshooting.html#node-inheritance-and-variable-scope Maybe you can create another class that handles ''server default''. Or create a custom fact that distinguishes these hosts from others. I personally don''t use my nodes to declare anything, I use a combination of classes, custom facts and extlookup of yaml files to describe my sites. Cheers, Den On 05/08/2011, at 18:25, Thomas Rasmussen <rasmussen.thomas@gmail.com> wrote:> Hi > > Thanks for the reply, that works, but I''d like to keep my include of > the sudoers::config in my default node section, but if I do that, then > I don''t have the $sudoenv variable available at that time. > > Is there any way of overriding a previously include of a class? I > tried to ''sudoers::config'': sudoenv=> $sudoenv, stage => install; in > my server-defaults node definition, but puppet gave me a duplicate > error on include. > > I''m running 2.6.4 on both server and client side. > > Regards > Thomas > > On Aug 5, 10:09 am, Denmat <tu2bg...@gmail.com> wrote: >> Hi, >> >> You setting sudoenv to default in the default node. That is not overridden by subsequent node declarations. >> >> If you are using 2.6 and above I would pass a parameter to the sudoers class. >> >>> class sudoers::config (env = ''default'') { >>> file { "/etc/sudoers": >>> ensure => file, >>> owner => "root", >>> group => "root", >>> mode => 440, >>> source => "puppet:///modules/sudoers/sudoers_ >>> ${env}", >>> } >> >> then maybe call like this. >> >>> node ''server-defaults'' inherits default { >>> class {"sudoers::config": env => ''custom_server'' } >>> } >> >> then >> >>> node default { >>> class {"sudoers::config": } >>> } >> >> That might help you. >> >> Cheers, >> Den >> On 05/08/2011, at 17:02, Thomas Rasmussen <rasmussen.tho...@gmail.com> wrote: >> >> >> >> >> >> >> >>> Hi >> >>> I''m having some trouble with the following setup: >> >>> node ''serverA'' inherits server-defaults { >>> include myApp::install >>> } >> >>> node ''server-defaults'' inherits default { >>> $sudoenv = ''custom_server'' >>> } >> >>> node default { >>> $sudoenv = ''default'' >>> include sudoers::config >>> } >> >>> class sudoers::config { >>> file { "/etc/sudoers": >>> ensure => file, >>> owner => "root", >>> group => "root", >>> mode => 440, >>> source => "puppet:///modules/sudoers/sudoers_ >>> $sudoenv", >>> } >>> } >> >>> I have then created to files: sudoers_default and >>> sudoers_custom_server >> >>> I want to have a default sudoers file on most of my servers, but on a >>> few others, I need a different one, but on serverA I only get the >>> sudoers_default file. I have tried to create it as a template (still >>> using the $sudoenv varialbe) but this does not have any effect. Only >>> if I move the include sudoers::config to the ''server-defaults'' node, >>> then it works as I want. >> >>> Being somewhat new to puppet, I really cant figure out how I can solve >>> this task, but hopefully somebody can give some good hints? >> >>> There isn''t any of my default variables that I can use instead of >>> $sudoenv. >> >>> Hope somebody has hints >> >>> Regards >>> Thomas >> >>> -- >>> 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 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. >-- 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.
vagn scott
2011-Aug-05 13:41 UTC
Re: [Puppet Users] Re: Variable scope when having node inheritance
On 08/05/2011 04:25 AM, Thomas Rasmussen wrote:> Is there any way of overriding a previously include of a class?Yes. See http://docs.puppetlabs.com/guides/troubleshooting.html#class-inheritance-and-variable-scope Something like (warning: untested): Class["Sudoers::Config"] { env => ''custom_server'', } Might do it. Then again, nodes are not classes, so it might not work. In which case, do your work in classes, and just use nodes to include the classes. -- vagn -- 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.
jcbollinger
2011-Aug-05 17:33 UTC
[Puppet Users] Re: Variable scope when having node inheritance
On Aug 5, 3:25 am, Thomas Rasmussen <rasmussen.tho...@gmail.com> wrote:> Hi > > Thanks for the reply, that works, but I''d like to keep my include of > the sudoers::config in my default node section, but if I do that, then > I don''t have the $sudoenv variable available at that time. > > Is there any way of overriding a previously include of a class? I > tried to ''sudoers::config'': sudoenv=> $sudoenv, stage => install; in > my server-defaults node definition, but puppet gave me a duplicate > error on include.Not to my knowledge, no. If Vagn''s suggestion for that works then I''ll be quite surprised, and also very interested in hearing about it.> I''m running 2.6.4 on both server and client side.Another alternative is to set the variable by means other than the node declaration. The extlookup() function can be quite useful for this sort of thing. Be aware that it looks like you are going to *have* to do something along these lines in order to upgrade to 2.8.x (when that arrives). Yet another alternative might be to prune your node inheritance tree into two, one rooted at ''default'' and a second rooted at ''server- default''. Each of those node declarations would define $sudoenv and include sudoers::config. If you want to adhere carefully to a DRY approach, then you can take everything common to the two node types, wrap it up in a class, and have each of the to default nodes include it. 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.