Hello, I would like to know what are the best pratices in node declaration. I tried to play with inheritance with failures : Here my* puppet/manifest/site.pp* node basenode {> class { ''ssh'': } > class { ''ntp'': } > class { ''users'': } > class { ''sudo'': } > } > > node default inherits basenode { > } > > ################################################################ > # serv1 > ################################################################ > node "serv1" inherits basenode { > class { ''sudo'' : > sudoers => "sudoers_serv1" > } > class { ''debug'': } > } >As you can see i have to manage 2 sudoers file : One in almost all server, and an other one in my "serv1" server here is my *sudo class* class sudo ($sudoers="sudoers") {> package { ''sudo'': > ensure => installed, > } > file { ''/etc/sudoers'': > source => "puppet://puppetmaster.foo.com/sudo/$sudoers", > ensure => file, > mode => 440, > owner => ''root'', > group => ''root'', > require => Package[''sudo''], > } > } >Can you tell me what is the best way to resolve that kind of problems. Thx -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/zoT3tKXyIUcJ. 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.
On 11/21/2012 06:46 PM, AnOnJoe wrote:> Hello, > > I would like to know what are the best pratices in node declaration. > > I tried to play with inheritance with failures : > Here my*puppet/manifest/site.pp* > > node basenode { > class { ''ssh'': } > class { ''ntp'': } > class { ''users'': } > class { ''sudo'': } > }First of all, don''t instant classes like resources... Use include instead. So this would look like: node basenode { include ssh include ntp include users include sudo }> > node default inherits basenode { > } > > ################################################################ > # serv1 > ################################################################ > node "serv1" inherits basenode { > class { ''sudo'' : > sudoers => "sudoers_serv1" > } > class { ''debug'': } > }When you instance classes like resources, then you cannot instance it twice. You can only do it once, and you already did it in the basenode. This is like defining the same resource twice. Your main problem is in the basenode.> As you can see i have to manage 2 sudoers file : > One in almost all server, and an other one in my "serv1" server > > here is my *sudo class* > > class sudo ($sudoers="sudoers") { > package { ''sudo'': > ensure => installed, > } > file { ''/etc/sudoers'': > source => > "puppet://puppetmaster.foo.com/sudo/$sudoers", > ensure => file, > mode => 440, > owner => ''root'', > group => ''root'', > require => Package[''sudo''], > }You can use Hiera for this purpose. In the hiera yaml manifests you can just then define something like: sudo::sudoers: sudoers_serv1 and your class would get the data from hiera. That way it would be enough to include it into basenode, and you would have opportunity to set up each node differently without redefining the classes. I really urge you to invest some time into learning hiera. -- 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.
Seconding this. When I first started using puppet, I thought that node inheritance would be a wonderful way to achieve a hierarchy. This was before I knew about hiera. Long story short, node inheritance doesn''t work that way, and if you try and force it to, things get really unpredictable. Hiera is definitely the way to go for this kind of structure. Best part is, once you get it going, you don''t even have to declare nodes anymore. all you need is a default node and hiera_include. node default { hiera_include(''classes'') } then just have an array of class names to include in your hiera files. For example, using the yaml backend with this hierarchy: :hierarchy: - %{fqdn} - common common.yaml would have classes: - ssh - ntp - users - sudo and (fqdn of serv1).yaml, along with what Jakov mentioned, would have classes: - debug With more complicated hierarchy''s, you can also get more complicated layers of classes. On Wednesday, November 21, 2012 10:27:41 AM UTC-8, Jakov Sosic wrote:> > On 11/21/2012 06:46 PM, AnOnJoe wrote: > > Hello, > > > > I would like to know what are the best pratices in node declaration. > > > > I tried to play with inheritance with failures : > > Here my*puppet/manifest/site.pp* > > > > node basenode { > > class { ''ssh'': } > > class { ''ntp'': } > > class { ''users'': } > > class { ''sudo'': } > > } > > > First of all, don''t instant classes like resources... Use include > instead. So this would look like: > > node basenode { > include ssh > include ntp > include users > include sudo > } > > > > > > node default inherits basenode { > > } > > > > ################################################################ > > # serv1 > > ################################################################ > > node "serv1" inherits basenode { > > class { ''sudo'' : > > sudoers => "sudoers_serv1" > > } > > class { ''debug'': } > > } > > When you instance classes like resources, then you cannot instance it > twice. You can only do it once, and you already did it in the basenode. > This is like defining the same resource twice. Your main problem is in > the basenode. > > > > As you can see i have to manage 2 sudoers file : > > One in almost all server, and an other one in my "serv1" server > > > > here is my *sudo class* > > > > class sudo ($sudoers="sudoers") { > > package { ''sudo'': > > ensure => installed, > > } > > file { ''/etc/sudoers'': > > source => > > "puppet://puppetmaster.foo.com/sudo/$sudoers", > > ensure => file, > > mode => 440, > > owner => ''root'', > > group => ''root'', > > require => Package[''sudo''], > > } > > You can use Hiera for this purpose. In the hiera yaml manifests you can > just then define something like: > > sudo::sudoers: sudoers_serv1 > > and your class would get the data from hiera. That way it would be > enough to include it into basenode, and you would have opportunity to > set up each node differently without redefining the classes. I really > urge you to invest some time into learning hiera. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/QEoKnNaXUUQJ. 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.
Thank you very much guys. Hiera saved my life ;-) Le mercredi 21 novembre 2012 18:46:06 UTC+1, AnOnJoe a écrit :> > Hello, > > I would like to know what are the best pratices in node declaration. > > I tried to play with inheritance with failures : > Here my* puppet/manifest/site.pp* > > node basenode { >> class { ''ssh'': } >> class { ''ntp'': } >> class { ''users'': } >> class { ''sudo'': } >> } >> >> node default inherits basenode { >> } >> >> ################################################################ >> # serv1 >> ################################################################ >> node "serv1" inherits basenode { >> class { ''sudo'' : >> sudoers => "sudoers_serv1" >> } >> class { ''debug'': } >> } >> > > As you can see i have to manage 2 sudoers file : > One in almost all server, and an other one in my "serv1" server > > here is my *sudo class* > > class sudo ($sudoers="sudoers") { >> package { ''sudo'': >> ensure => installed, >> } >> file { ''/etc/sudoers'': >> source => "puppet://puppetmaster.foo.com/sudo/$sudoers", >> ensure => file, >> mode => 440, >> owner => ''root'', >> group => ''root'', >> require => Package[''sudo''], >> } >> } >> > > > Can you tell me what is the best way to resolve that kind of problems. > > Thx >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/Q416Qk8wJgYJ. 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.