Hello all, I am trying to write a syslog module for our small puppet installation. Since I''d like to learn how to write puppet classes/modules I would avoid modules from puppet labs forge (at least for now). This module is going to be deployed on RH 5 _and_ 6. In our infrastructure each RH line (5 or 6) is configured differently: RH 5 uses sysklogd, RH 6 uses rsyslog. I have written a class but as you can see it has a lot of redundant code. Can I use any puppet syntax to make it more elegant (and easier to maintain :-) ) ? Can you suggest anything ? class syslog::install { case $lsbmajdistrelease { ''5'': { package { "sysklogd": ensure => present, } } ''6'': { package { "rsyslog": ensure => present, } } } } class syslog::config { case $lsbmajdistrelease { ''5'': { file { "/etc/syslog.conf": ensure => present, owner => ''root'', group => ''root'', mode => 0644, source => "puppet:///modules/syslog/syslog.conf", require => Class["syslog::install"], notify => Class["syslog::service"], } } ''6'': { file { "/etc/rsyslog.conf": ensure => present, owner => ''root'', group => ''root'', mode => 0644, source => "puppet:///modules/syslog/rsyslog.conf", require => Class["syslog::install"], notify => Class["syslog::service"], } } } } class syslog::service { case $lsbmajdistrelease { ''5'': { service { "syslog": ensure => runing, enable => true, require => Class["syslog::config"], } } ''6'': { service { "rsyslog": ensure => runing, enable => true, require => Class["syslog::config"], } } } } class syslog { include syslog::install, syslog::config, syslog::service } Thanks in advance :-) Przemek -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Gavin Williams
2013-Apr-09 09:47 UTC
[Puppet Users] Re: How to optimize puppet class/module code ?
Hi there, I think you''re quickest win for making the code cleaner and easier would be to create a ::params class, which sets the correct values for package, file and service based on your distro. Can then inherit this class on your ::install, ::config and ::service classes. I''m sure other people will chime in with some other ideas aswell :) HTH Gav On Tuesday, 9 April 2013 10:36:51 UTC+1, ForumUser wrote:> > Hello all, > > I am trying to write a syslog module for our small puppet installation. > Since I''d like to learn how to write puppet classes/modules I would avoid > modules from puppet labs forge (at least for now). > > This module is going to be deployed on RH 5 _and_ 6. > In our infrastructure each RH line (5 or 6) is configured differently: > RH 5 uses sysklogd, RH 6 uses rsyslog. > > I have written a class but as you can see it has a lot of redundant code. > Can I use any puppet syntax to make it more elegant (and easier to > maintain :-) ) ? > Can you suggest anything ? > > class syslog::install { > case $lsbmajdistrelease { > ''5'': { > package { "sysklogd": > ensure => present, > } > } > > ''6'': { > package { "rsyslog": > ensure => present, > } > } > } > } > > class syslog::config { > case $lsbmajdistrelease { > ''5'': { > file { "/etc/syslog.conf": > ensure => present, > owner => ''root'', > group => ''root'', > mode => 0644, > source => > "puppet:///modules/syslog/syslog.conf", > require => > Class["syslog::install"], > notify => Class["syslog::service"], > } > } > > ''6'': { > file { "/etc/rsyslog.conf": > ensure => present, > owner => ''root'', > group => ''root'', > mode => 0644, > source => > "puppet:///modules/syslog/rsyslog.conf", > require => > Class["syslog::install"], > notify => Class["syslog::service"], > } > } > } > } > > class syslog::service { > case $lsbmajdistrelease { > ''5'': { > service { "syslog": > ensure => runing, > enable => true, > require => Class["syslog::config"], > } > } > > ''6'': { > service { "rsyslog": > ensure => runing, > enable => true, > require => Class["syslog::config"], > } > } > } > } > > > class syslog { > include syslog::install, syslog::config, syslog::service > } > > > Thanks in advance :-) > Przemek > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
ForumUser
2013-Apr-09 09:54 UTC
[Puppet Users] Re: How to optimize puppet class/module code ?
Hi Gavin, Can you suggest any URL where I could read about ::params classes (and examples of course ;-) ) ? On Tuesday, 9 April 2013 10:47:40 UTC+1, Gavin Williams wrote:> > Hi there, > > I think you''re quickest win for making the code cleaner and easier would > be to create a ::params class, which sets the correct values for package, > file and service based on your distro. > > Can then inherit this class on your ::install, ::config and ::service > classes. > > I''m sure other people will chime in with some other ideas aswell :) > > HTH > > Gav > > On Tuesday, 9 April 2013 10:36:51 UTC+1, ForumUser wrote: >> >> Hello all, >> >> I am trying to write a syslog module for our small puppet installation. >> Since I''d like to learn how to write puppet classes/modules I would avoid >> modules from puppet labs forge (at least for now). >> >> This module is going to be deployed on RH 5 _and_ 6. >> In our infrastructure each RH line (5 or 6) is configured differently: >> RH 5 uses sysklogd, RH 6 uses rsyslog. >> >> I have written a class but as you can see it has a lot of redundant code. >> Can I use any puppet syntax to make it more elegant (and easier to >> maintain :-) ) ? >> Can you suggest anything ? >> >> class syslog::install { >> case $lsbmajdistrelease { >> ''5'': { >> package { "sysklogd": >> ensure => present, >> } >> } >> >> ''6'': { >> package { "rsyslog": >> ensure => present, >> } >> } >> } >> } >> >> class syslog::config { >> case $lsbmajdistrelease { >> ''5'': { >> file { "/etc/syslog.conf": >> ensure => present, >> owner => ''root'', >> group => ''root'', >> mode => 0644, >> source => >> "puppet:///modules/syslog/syslog.conf", >> require => >> Class["syslog::install"], >> notify => >> Class["syslog::service"], >> } >> } >> >> ''6'': { >> file { "/etc/rsyslog.conf": >> ensure => present, >> owner => ''root'', >> group => ''root'', >> mode => 0644, >> source => >> "puppet:///modules/syslog/rsyslog.conf", >> require => >> Class["syslog::install"], >> notify => >> Class["syslog::service"], >> } >> } >> } >> } >> >> class syslog::service { >> case $lsbmajdistrelease { >> ''5'': { >> service { "syslog": >> ensure => runing, >> enable => true, >> require => >> Class["syslog::config"], >> } >> } >> >> ''6'': { >> service { "rsyslog": >> ensure => runing, >> enable => true, >> require => >> Class["syslog::config"], >> } >> } >> } >> } >> >> >> class syslog { >> include syslog::install, syslog::config, syslog::service >> } >> >> >> Thanks in advance :-) >> Przemek >> >>-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
fatmcgav
2013-Apr-09 09:56 UTC
Re: [Puppet Users] Re: How to optimize puppet class/module code ?
http://soimasysadmin.com/2012/02/29/puppet-inheritance-revisited/ is one I''ve got bookmarked... HTH Gav On 9 April 2013 10:54, ForumUser <p.bak@cmcmarkets.com> wrote:> Hi Gavin, > > Can you suggest any URL where I could read about ::params classes (and > examples of course ;-) ) ? > > On Tuesday, 9 April 2013 10:47:40 UTC+1, Gavin Williams wrote: >> >> Hi there, >> >> I think you''re quickest win for making the code cleaner and easier would >> be to create a ::params class, which sets the correct values for package, >> file and service based on your distro. >> >> Can then inherit this class on your ::install, ::config and ::service >> classes. >> >> I''m sure other people will chime in with some other ideas aswell :) >> >> HTH >> >> Gav >> >> On Tuesday, 9 April 2013 10:36:51 UTC+1, ForumUser wrote: >>> >>> Hello all, >>> >>> I am trying to write a syslog module for our small puppet installation. >>> Since I''d like to learn how to write puppet classes/modules I would avoid >>> modules from puppet labs forge (at least for now). >>> >>> This module is going to be deployed on RH 5 _and_ 6. >>> In our infrastructure each RH line (5 or 6) is configured differently: >>> RH 5 uses sysklogd, RH 6 uses rsyslog. >>> >>> I have written a class but as you can see it has a lot of redundant code. >>> Can I use any puppet syntax to make it more elegant (and easier to >>> maintain :-) ) ? >>> Can you suggest anything ? >>> >>> class syslog::install { >>> case $lsbmajdistrelease { >>> ''5'': { >>> ** package { "sysklogd": >>> ** ensure => present, >>> ** } >>> } >>> >>> ''6'': { >>> ** package { "rsyslog": >>> ** ensure => present, >>> ** } >>> } >>> } >>> } >>> >>> class syslog::config { >>> case $lsbmajdistrelease { >>> ''5'': { >>> ** file { "/etc/syslog.conf": >>> ** ensure => present, >>> ** owner => ''root'', >>> ** group => ''root'', >>> ** mode => 0644, >>> ** source => >>> "puppet:///modules/syslog/**syslog.conf", >>> ** require => >>> Class["syslog::install"], >>> ** notify => >>> Class["syslog::service"], >>> ** } >>> } >>> >>> ''6'': { >>> ** file { "/etc/rsyslog.conf": >>> ** ensure => present, >>> ** owner => ''root'', >>> ** group => ''root'', >>> ** mode => 0644, >>> ** source => >>> "puppet:///modules/syslog/**rsyslog.conf", >>> ** require => >>> Class["syslog::install"], >>> ** notify => >>> Class["syslog::service"], >>> ** } >>> } >>> } >>> } >>> >>> class syslog::service { >>> case $lsbmajdistrelease { >>> ''5'': { >>> ** service { "syslog": >>> ** ensure => runing, >>> ** enable => true, >>> ** require => >>> Class["syslog::config"], >>> ** } >>> } >>> >>> ''6'': { >>> ** service { "rsyslog": >>> ** ensure => runing, >>> ** enable => true, >>> ** require => >>> Class["syslog::config"], >>> ** } >>> } >>> } >>> } >>> >>> >>> class syslog { >>> include syslog::install, syslog::config, syslog::service >>> } >>> >>> >>> Thanks in advance :-) >>> Przemek >>> >>> -- > You received this message because you are subscribed to a topic in the > Google Groups "Puppet Users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/puppet-users/vJeR5M2-TS0/unsubscribe?hl=en > . > To unsubscribe from this group and all its topics, send an email to > puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Stefan Heijmans
2013-Apr-09 10:23 UTC
[Puppet Users] Re: How to optimize puppet class/module code ?
Or checkout this one from Ken Barber; modern module development http://www.slideshare.net/PuppetLabs/modern-module-development-ken-barber-2012-edinburgh-puppet-camp http://www.youtube.com/watch?v=zNXSKv6987g -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
ForumUser
2013-Apr-09 11:51 UTC
Re: [Puppet Users] Re: How to optimize puppet class/module code ?
I have looked at this example. But what is a difference between ''File'' and ''file'' keyword ? Where I can read more about it ? On Tuesday, 9 April 2013 10:56:30 UTC+1, Gavin Williams wrote:> > http://soimasysadmin.com/2012/02/29/puppet-inheritance-revisited/ is one > I''ve got bookmarked... > > HTH > > Gav > > > On 9 April 2013 10:54, ForumUser <p....@cmcmarkets.com <javascript:>>wrote: > >> Hi Gavin, >> >> Can you suggest any URL where I could read about ::params classes (and >> examples of course ;-) ) ? >> >> On Tuesday, 9 April 2013 10:47:40 UTC+1, Gavin Williams wrote: >>> >>> Hi there, >>> >>> I think you''re quickest win for making the code cleaner and easier would >>> be to create a ::params class, which sets the correct values for package, >>> file and service based on your distro. >>> >>> Can then inherit this class on your ::install, ::config and ::service >>> classes. >>> >>> I''m sure other people will chime in with some other ideas aswell :) >>> >>> HTH >>> >>> Gav >>> >>> On Tuesday, 9 April 2013 10:36:51 UTC+1, ForumUser wrote: >>>> >>>> Hello all, >>>> >>>> I am trying to write a syslog module for our small puppet installation. >>>> Since I''d like to learn how to write puppet classes/modules I would >>>> avoid >>>> modules from puppet labs forge (at least for now). >>>> >>>> This module is going to be deployed on RH 5 _and_ 6. >>>> In our infrastructure each RH line (5 or 6) is configured differently: >>>> RH 5 uses sysklogd, RH 6 uses rsyslog. >>>> >>>> I have written a class but as you can see it has a lot of redundant >>>> code. >>>> Can I use any puppet syntax to make it more elegant (and easier to >>>> maintain :-) ) ? >>>> Can you suggest anything ? >>>> >>>> class syslog::install { >>>> case $lsbmajdistrelease { >>>> ''5'': { >>>> ** package { "sysklogd": >>>> ** ensure => present, >>>> ** } >>>> } >>>> >>>> ''6'': { >>>> ** package { "rsyslog": >>>> ** ensure => present, >>>> ** } >>>> } >>>> } >>>> } >>>> >>>> class syslog::config { >>>> case $lsbmajdistrelease { >>>> ''5'': { >>>> ** file { "/etc/syslog.conf": >>>> ** ensure => present, >>>> ** owner => ''root'', >>>> ** group => ''root'', >>>> ** mode => 0644, >>>> ** source => >>>> "puppet:///modules/syslog/**syslog.conf", >>>> ** require => >>>> Class["syslog::install"], >>>> ** notify => >>>> Class["syslog::service"], >>>> ** } >>>> } >>>> >>>> ''6'': { >>>> ** file { "/etc/rsyslog.conf": >>>> ** ensure => present, >>>> ** owner => ''root'', >>>> ** group => ''root'', >>>> ** mode => 0644, >>>> ** source => >>>> "puppet:///modules/syslog/**rsyslog.conf", >>>> ** require => >>>> Class["syslog::install"], >>>> ** notify => >>>> Class["syslog::service"], >>>> ** } >>>> } >>>> } >>>> } >>>> >>>> class syslog::service { >>>> case $lsbmajdistrelease { >>>> ''5'': { >>>> ** service { "syslog": >>>> ** ensure => runing, >>>> ** enable => true, >>>> ** require => >>>> Class["syslog::config"], >>>> ** } >>>> } >>>> >>>> ''6'': { >>>> ** service { "rsyslog": >>>> ** ensure => runing, >>>> ** enable => true, >>>> ** require => >>>> Class["syslog::config"], >>>> ** } >>>> } >>>> } >>>> } >>>> >>>> >>>> class syslog { >>>> include syslog::install, syslog::config, syslog::service >>>> } >>>> >>>> >>>> Thanks in advance :-) >>>> Przemek >>>> >>>> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Puppet Users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/puppet-users/vJeR5M2-TS0/unsubscribe?hl=en >> . >> To unsubscribe from this group and all its topics, send an email to >> puppet-users...@googlegroups.com <javascript:>. >> To post to this group, send email to puppet...@googlegroups.com<javascript:> >> . >> Visit this group at http://groups.google.com/group/puppet-users?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
ForumUser
2013-Apr-09 13:16 UTC
[Puppet Users] Re: How to optimize puppet class/module code ?
Hi there, after reading the code I have changed my puppet code to the following (thanks ! - it is now much more readable :-) ). But I don''t know how to change the "source =>" from syslog::config class to be universal. Could you please help me ? class syslog::params { case $lsbmajdistrelease { ''5'': { $syslog_package_name = ''sysklogd'' $syslog_syslog_config = ''/etc/ syslog.conf'' $syslog_service_name = ''syslog'' } ''6'': { $syslog_package_name = ''rsyslog'' $syslog_syslog_config = ''/etc/ rsyslog.conf'' $syslog_service_name = ''rsyslog'' } } } class syslog::install { package { $syslog::params::syslog_package_name: ensure => installed, } } class syslog::config { file { $syslog::params::syslog_config: ensure => present, owner => ''root'', group => ''root'', mode => 0644, source => "puppet:///modules/syslog/syslog.conf", require => Class["syslog::install"], notify => Class["syslog::service"], } } class syslog::service { service { $syslog::params::syslog_service_name: ensure => runing, enable => true, require => Class["syslog::config"], } } class syslog { include syslog::params, syslog::install, syslog::config, syslog::service } On 9 Apr, 05:47, Gavin Williams <fatmc...@gmail.com> wrote:> Hi there, > > I think you''re quickest win for making the code cleaner and easier would be > to create a ::params class, which sets the correct values for package, file > and service based on your distro. > > Can then inherit this class on your ::install, ::config and ::service > classes. > > I''m sure other people will chime in with some other ideas aswell :) > > HTH > > Gav > > > > > > > > On Tuesday, 9 April 2013 10:36:51 UTC+1, ForumUser wrote: > > > Hello all, > > > I am trying to write a syslog module for our small puppet installation. > > Since I''d like to learn how to write puppet classes/modules I would avoid > > modules from puppet labs forge (at least for now). > > > This module is going to be deployed on RH 5 _and_ 6. > > In our infrastructure each RH line (5 or 6) is configured differently: > > RH 5 uses sysklogd, RH 6 uses rsyslog. > > > I have written a class but as you can see it has a lot of redundant code. > > Can I use any puppet syntax to make it more elegant (and easier to > > maintain :-) ) ? > > Can you suggest anything ? > > > class syslog::install { > > case $lsbmajdistrelease { > > ''5'': { > > package { "sysklogd": > > ensure => present, > > } > > } > > > ''6'': { > > package { "rsyslog": > > ensure => present, > > } > > } > > } > > } > > > class syslog::config { > > case $lsbmajdistrelease { > > ''5'': { > > file { "/etc/syslog.conf": > > ensure => present, > > owner => ''root'', > > group => ''root'', > > mode => 0644, > > source => > > "puppet:///modules/syslog/syslog.conf", > > require => > > Class["syslog::install"], > > notify => Class["syslog::service"], > > } > > } > > > ''6'': { > > file { "/etc/rsyslog.conf": > > ensure => present, > > owner => ''root'', > > group => ''root'', > > mode => 0644, > > source => > > "puppet:///modules/syslog/rsyslog.conf", > > require => > > Class["syslog::install"], > > notify => Class["syslog::service"], > > } > > } > > } > > } > > > class syslog::service { > > case $lsbmajdistrelease { > > ''5'': { > > service { "syslog": > > ensure => runing, > > enable => true, > > require => Class["syslog::config"], > > } > > } > > > ''6'': { > > service { "rsyslog": > > ensure => runing, > > enable => true, > > require => Class["syslog::config"], > > } > > } > > } > > } > > > class syslog { > > include syslog::install, syslog::config, syslog::service > > } > > > Thanks in advance :-) > > Przemek-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Stefan Heijmans
2013-Apr-10 09:11 UTC
[Puppet Users] Re: How to optimize puppet class/module code ?
You could use sourceselect in source; http://docs.puppetlabs.com/references/stable/type.html#file or use parameter in the source statement; source => "puppet:///modules/syslog/syslog.conf_${::$lsbmajdistrelease}", and create 2 syslog.conf files in the files directory; syslog.conf_5 syslog.conf_6 -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Stefan Heijmans
2013-Apr-10 09:23 UTC
[Puppet Users] Re: How to optimize puppet class/module code ?
bad cp; source => "puppet:///modules/syslog/syslog.conf_${::lsbmajdistrelease}", -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Apr-10 14:07 UTC
[Puppet Users] Re: How to optimize puppet class/module code ?
On Tuesday, April 9, 2013 4:47:40 AM UTC-5, Gavin Williams wrote:> > Hi there, > > I think you''re quickest win for making the code cleaner and easier would > be to create a ::params class, which sets the correct values for package, > file and service based on your distro. > >A ::params class is a reasonable approach, but the *quickest* win would be to do the equivalent within the existing code, without creating a new class. For example: class syslog::install { $syslog_package = $lsbmajdistrelease ? { ''5'' => ''sysklogd'', ''6'' => ''rsyslog'' } package { ${syslog_package}: ensure => present } } Note also that even if the data ($syslog_package in this example) were pulled out to a separate ::params class, it would be undesirable to use class inheritance to ensure the data are initialized. It is sufficient and preferable in this case to simply ''include'' the ::params class at the beginning of the class using it. Class inheritance would be needed only if the other classes were parameterized AND variables from the ::params class were used as parameter default values. 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.