Alexandre
2011-Oct-13 10:16 UTC
[Puppet Users] How to inherit a parameterized class ? What is the syntax ?
Hi, I am trying to manage the puppet.conf file, but both my classes ''puppet'' and ''puppet::master'' need to manage it. Basically, the class ''puppet::master'' should be able to override the resource, which could be done by inheritance. My problem is that my class ''puppet'' is a parameterized class: class puppet ( $puppetmaster_fqdn ) { file { ''/etc/puppet/puppet.conf'': content => template(''puppet/puppet.conf.erb''), } # (...) } and so, i don''t find any syntax to inherit from it: class puppet::master ( $with_dashboard = ''yes'', $with_cloud_provisioner = ''no'' ) inherits puppet { # (...) } fails with err: Could not retrieve catalog from remote server: Error 400 on SERVER: Must pass puppetmaster_fqdn to Class[Puppet] at /etc/puppet/ modules/puppet/manifests/puppet.pp:1 on node (...) I tried different ways to declare my class ''puppet::master'', but i do not find the right syntax, it always fails class puppet::master ( $puppetmaster_fqdn = ''something'', $with_dashboard = ''yes'', $with_cloud_provisioner = ''no'' ) inherits puppet { # (...) } class puppet::master ( $with_dashboard = ''yes'', $with_cloud_provisioner = ''no'' ) inherits puppet( puppetmaster_fqdn => ''something'' ) { # (...) } What is the good syntax for that ? Note also that i tried to work around the problem by using a virtual resource for my File[''/etc/puppet.conf''], and realize it in both classes (without inheritance) but it did not end up as i wished. It worked, but the templated file missed the content which should have been triggered by the variables $with_dashboard from class ''puppet::master'' -- 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.
Nan Liu
2011-Oct-13 15:33 UTC
Re: [Puppet Users] How to inherit a parameterized class ? What is the syntax ?
On Thu, Oct 13, 2011 at 3:16 AM, Alexandre <alexandre.fouche@gmail.com> wrote:> Hi, > > I am trying to manage the puppet.conf file, but both my classes > ''puppet'' and ''puppet::master'' need to manage it. Basically, the class > ''puppet::master'' should be able to override the resource, which could > be done by inheritance. > My problem is that my class ''puppet'' is a parameterized class: > > class puppet ( $puppetmaster_fqdn ) { > file { ''/etc/puppet/puppet.conf'': > content => template(''puppet/puppet.conf.erb''), > } > # (...) > } > > and so, i don''t find any syntax to inherit from it: > > class puppet::master ( $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet { > # (...) > } > > fails with > > err: Could not retrieve catalog from remote server: Error 400 on > SERVER: Must pass puppetmaster_fqdn to Class[Puppet] at /etc/puppet/ > modules/puppet/manifests/puppet.pp:1 on node (...) > > I tried different ways to declare my class ''puppet::master'', but i do > not find the right syntax, it always fails > > class puppet::master ( $puppetmaster_fqdn = ''something'', > $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet { > # (...) > } > > class puppet::master ( $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet( puppetmaster_fqdn => > ''something'' ) { > # (...) > } > > What is the good syntax for that ?There''s probably three ways to tackle it: 1. have the puppet class write a file called puppet.conf.agent, and the master class write puppet.conf.master and cat puppet.conf.* > puppet.conf. 2. use a variable and add some logic to the ERB template. 3. use the following syntax (be aware it realize and override): In class puppet::master: File <| title==''/etc/puppet/puppet.conf'' |> { content => template(''puppet/puppetmaster.conf.erb''), } HTH, Nan -- 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.
Henrik Lindberg
2011-Oct-14 00:11 UTC
Re: [Puppet Users] How to inherit a parameterized class ? What is the syntax ?
Don''t know if I am out on a limb here, but did you try setting class defaults? class puppet::master inherits puppet { class { ''puppet'': puppetmaster_fqdn => "my wanted value" } # ... } - henrik On 10/13/11 12:16 PM, Alexandre wrote:> Hi, > > I am trying to manage the puppet.conf file, but both my classes > ''puppet'' and ''puppet::master'' need to manage it. Basically, the class > ''puppet::master'' should be able to override the resource, which could > be done by inheritance. > My problem is that my class ''puppet'' is a parameterized class: > > class puppet ( $puppetmaster_fqdn ) { > file { ''/etc/puppet/puppet.conf'': > content => template(''puppet/puppet.conf.erb''), > } > # (...) > } > > and so, i don''t find any syntax to inherit from it: > > class puppet::master ( $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet { > # (...) > } > > fails with > > err: Could not retrieve catalog from remote server: Error 400 on > SERVER: Must pass puppetmaster_fqdn to Class[Puppet] at /etc/puppet/ > modules/puppet/manifests/puppet.pp:1 on node (...) > > I tried different ways to declare my class ''puppet::master'', but i do > not find the right syntax, it always fails > > class puppet::master ( $puppetmaster_fqdn = ''something'', > $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet { > # (...) > } > > class puppet::master ( $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet( puppetmaster_fqdn => > ''something'' ) { > # (...) > } > > What is the good syntax for that ? > > > Note also that i tried to work around the problem by using a virtual > resource for my File[''/etc/puppet.conf''], and realize it in both > classes (without inheritance) but it did not end up as i wished. It > worked, but the templated file missed the content which should have > been triggered by the variables $with_dashboard from class > ''puppet::master'' >-- 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-Oct-14 13:04 UTC
[Puppet Users] Re: How to inherit a parameterized class ? What is the syntax ?
On Oct 13, 5:16 am, Alexandre <alexandre.fou...@gmail.com> wrote:> Hi, > > I am trying to manage the puppet.conf file, but both my classes > ''puppet'' and ''puppet::master'' need to manage it. Basically, the class > ''puppet::master'' should be able to override the resource, which could > be done by inheritance. > My problem is that my class ''puppet'' is a parameterized class: > > class puppet ( $puppetmaster_fqdn ) { > file { ''/etc/puppet/puppet.conf'': > content => template(''puppet/puppet.conf.erb''), > } > # (...) > } > > and so, i don''t find any syntax to inherit from it: > > class puppet::master ( $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet { > # (...) > } > > fails with > > err: Could not retrieve catalog from remote server: Error 400 on > SERVER: Must pass puppetmaster_fqdn to Class[Puppet] at /etc/puppet/ > modules/puppet/manifests/puppet.pp:1 on node (...) > > I tried different ways to declare my class ''puppet::master'', but i do > not find the right syntax, it always fails > > class puppet::master ( $puppetmaster_fqdn = ''something'', > $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet { > # (...) > } > > class puppet::master ( $with_dashboard = ''yes'', > $with_cloud_provisioner = ''no'' > ) inherits puppet( puppetmaster_fqdn => > ''something'' ) { > # (...) > } > > What is the good syntax for that ? > > Note also that i tried to work around the problem by using a virtual > resource for my File[''/etc/puppet.conf''], and realize it in both > classes (without inheritance) but it did not end up as i wished. It > worked, but the templated file missed the content which should have > been triggered by the variables $with_dashboard from class > ''puppet::master''To the best of my knowledge, you cannot inherit from a parameterized class. It is one of the lesser of the several reasons I don''t like them. There are a few of ways you can approach the problem: 1) Merge everything into one class. Use variables / external data / parameters to determine whether to include the puppetmaster parts. This is more or less Nan''s #2. 2) Remove your class parameterization, at least of the class puppet::puppet, so that class puppet::master can inherit from it. Class puppet::puppet can obtain an needed data from global variables or from an external source (i.e. via extlookup() or hiera). 3) Model separate sections of puppet.conf as separate resources, using, for instance, the Puppet-concat module. This is similar to Nan''s #1, but managed at a higher level. I do not recommend Nan''s #3 (overriding a resource parameter when you realize File[''/etc/puppet/puppet.conf'']) because it''s a maintenance problem waiting to bite you. With that said, however, it probably does perform the job you want. 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.
Henrik Lindberg
2011-Oct-14 13:50 UTC
Re: [Puppet Users] Re: How to inherit a parameterized class ? What is the syntax ?
On 10/14/11 3:04 PM, jcbollinger wrote:> On Oct 13, 5:16 am, Alexandre<alexandre.fou...@gmail.com> wrote:> To the best of my knowledge, you cannot inherit from a parameterized > class. It is one of the lesser of the several reasons I don''t like > them.This issue seems relevant: http://projects.puppetlabs.com/issues/4534 which is fixed in 2.6.3. As far as I understand, you either have to set defaults in the parametrized class, or set them using class defaults (there is no syntax to both inherit and set the parameter values). Regards - henrik -- 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-Oct-17 13:04 UTC
[Puppet Users] Re: How to inherit a parameterized class ? What is the syntax ?
On Oct 14, 8:50 am, Henrik Lindberg <henrik.lindb...@cloudsmith.com> wrote:> On 10/14/11 3:04 PM, jcbollinger wrote: > > > On Oct 13, 5:16 am, Alexandre<alexandre.fou...@gmail.com> wrote: > > To the best of my knowledge, you cannot inherit from a parameterized > > class. It is one of the lesser of the several reasons I don''t like > > them. > > This issue seems relevant:http://projects.puppetlabs.com/issues/4534 > which is fixed in 2.6.3. > > As far as I understand, you either have to set defaults in the > parametrized class, or set them using class defaultsHmm. Issue 4534 is about a parameterized class inheriting an *un*parameterized one, but it may be that inheriting a parameterized one could work as well under the conditions you describe. Nevertheless, the situations must few and narrow where it makes sense to parameterize the base class, yet it is satisfactory for subclasses to inherit default configuration. That''s certainly not the case for the OP. 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.
Alexandre Fouché
2011-Oct-18 11:02 UTC
Re: [Puppet Users] Re: How to inherit a parameterized class ? What is the syntax ?
Hi all, thanks for your answers, After some though and to keep it simple, i think the simplest way is to simply merge the two classes as you proposed, and decide the behaviour with a parameter. As stupid as it is, i admit i did not even though about it, i was seeing my current puppet class organisation and tried to go from there, but i should have seen from a bit higher and rethink how to solve the problems from my requirements and not from what i already had coded ! 2011/10/14 jcbollinger <John.Bollinger@stjude.org>> > > On Oct 13, 5:16 am, Alexandre <alexandre.fou...@gmail.com> wrote: > > Hi, > > > > I am trying to manage the puppet.conf file, but both my classes > > ''puppet'' and ''puppet::master'' need to manage it. Basically, the class > > ''puppet::master'' should be able to override the resource, which could > > be done by inheritance. > > My problem is that my class ''puppet'' is a parameterized class: > > > > class puppet ( $puppetmaster_fqdn ) { > > file { ''/etc/puppet/puppet.conf'': > > content => template(''puppet/puppet.conf.erb''), > > } > > # (...) > > } > > > > and so, i don''t find any syntax to inherit from it: > > > > class puppet::master ( $with_dashboard = ''yes'', > > $with_cloud_provisioner = ''no'' > > ) inherits puppet { > > # (...) > > } > > > > fails with > > > > err: Could not retrieve catalog from remote server: Error 400 on > > SERVER: Must pass puppetmaster_fqdn to Class[Puppet] at /etc/puppet/ > > modules/puppet/manifests/puppet.pp:1 on node (...) > > > > I tried different ways to declare my class ''puppet::master'', but i do > > not find the right syntax, it always fails > > > > class puppet::master ( $puppetmaster_fqdn = ''something'', > > $with_dashboard = ''yes'', > > $with_cloud_provisioner = ''no'' > > ) inherits puppet { > > # (...) > > } > > > > class puppet::master ( $with_dashboard = ''yes'', > > $with_cloud_provisioner = ''no'' > > ) inherits puppet( puppetmaster_fqdn => > > ''something'' ) { > > # (...) > > } > > > > What is the good syntax for that ? > > > > Note also that i tried to work around the problem by using a virtual > > resource for my File[''/etc/puppet.conf''], and realize it in both > > classes (without inheritance) but it did not end up as i wished. It > > worked, but the templated file missed the content which should have > > been triggered by the variables $with_dashboard from class > > ''puppet::master'' > > > To the best of my knowledge, you cannot inherit from a parameterized > class. It is one of the lesser of the several reasons I don''t like > them. > > There are a few of ways you can approach the problem: > > 1) Merge everything into one class. Use variables / external data / > parameters to determine whether to include the puppetmaster parts. > This is more or less Nan''s #2. > > 2) Remove your class parameterization, at least of the class > puppet::puppet, so that class puppet::master can inherit from it. > Class puppet::puppet can obtain an needed data from global variables > or from an external source (i.e. via extlookup() or hiera). > > 3) Model separate sections of puppet.conf as separate resources, > using, for instance, the Puppet-concat module. This is similar to > Nan''s #1, but managed at a higher level. > > I do not recommend Nan''s #3 (overriding a resource parameter when you > realize File[''/etc/puppet/puppet.conf'']) because it''s a maintenance > problem waiting to bite you. With that said, however, it probably > does perform the job you want. > > > 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. > >-- 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.
Alexandre Fouché
2011-Oct-18 11:08 UTC
Re: [Puppet Users] How to inherit a parameterized class ? What is the syntax ?
Hi, The 3rd option is interesting, i should try it to see. So far i had tried a similar way, with a "realize", but instead of overriding the content file, i had some conditional blocks with a variable in the puppet.conf.erb file. And it did not work, because it seems the variable was never known at the time of the first "realize" call (by the class puppet). But with a content overide, it should work, i suppose 2011/10/13 Nan Liu <nan@puppetlabs.com>> On Thu, Oct 13, 2011 at 3:16 AM, Alexandre <alexandre.fouche@gmail.com> > wrote: > > Hi, > > > > I am trying to manage the puppet.conf file, but both my classes > > ''puppet'' and ''puppet::master'' need to manage it. Basically, the class > > ''puppet::master'' should be able to override the resource, which could > > be done by inheritance. > > My problem is that my class ''puppet'' is a parameterized class: > > > > class puppet ( $puppetmaster_fqdn ) { > > file { ''/etc/puppet/puppet.conf'': > > content => template(''puppet/puppet.conf.erb''), > > } > > # (...) > > } > > > > and so, i don''t find any syntax to inherit from it: > > > > class puppet::master ( $with_dashboard = ''yes'', > > $with_cloud_provisioner = ''no'' > > ) inherits puppet { > > # (...) > > } > > > > fails with > > > > err: Could not retrieve catalog from remote server: Error 400 on > > SERVER: Must pass puppetmaster_fqdn to Class[Puppet] at /etc/puppet/ > > modules/puppet/manifests/puppet.pp:1 on node (...) > > > > I tried different ways to declare my class ''puppet::master'', but i do > > not find the right syntax, it always fails > > > > class puppet::master ( $puppetmaster_fqdn = ''something'', > > $with_dashboard = ''yes'', > > $with_cloud_provisioner = ''no'' > > ) inherits puppet { > > # (...) > > } > > > > class puppet::master ( $with_dashboard = ''yes'', > > $with_cloud_provisioner = ''no'' > > ) inherits puppet( puppetmaster_fqdn => > > ''something'' ) { > > # (...) > > } > > > > What is the good syntax for that ? > > There''s probably three ways to tackle it: > 1. have the puppet class write a file called puppet.conf.agent, and > the master class write puppet.conf.master and cat puppet.conf.* > > puppet.conf. > 2. use a variable and add some logic to the ERB template. > 3. use the following syntax (be aware it realize and override): > > In class puppet::master: > > File <| title==''/etc/puppet/puppet.conf'' |> { > content => template(''puppet/puppetmaster.conf.erb''), > } > > HTH, > > Nan > > -- > 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.