Alessandro Franceschi
2011-Oct-25 22:25 UTC
[Puppet Users] How to access to all the parameters of a parametrized class or a define
Dear all, is there a way to access in a template to all the parameters that are passed/defined in a class? I mean, something like: file { "puppi_openssh": path => "${settings::vardir}/puppi/openssh", mode => "0640", owner => "root", group => "root", ensure => present, content => inline_template("<%= scope.to_yaml %>"), } but instead of accessing to all the variables in the scope (as in scope.to_yaml ) I want to show only the variables passed to a parametrized class or a define (something like: openssh::*.to_yaml ) The point is to have a quick and generic way to pass Puppet knowledge (the variables defined/used) about a class, to a local file, that can be used in various interesting ways. If there''s no way to do that, does anyone find this worth a feature request? Best, Alessandro Franceschi -- 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.
Ken Barber
2011-Oct-25 23:10 UTC
Re: [Puppet Users] How to access to all the parameters of a parametrized class or a define
Hi Al :-). I''ve been working on this for the kwalify module so I can validate the inputs for a resource/class: https://github.com/kbarber/puppetlabs-kwalify/blob/ticket/10136-get_scope_args/lib/puppet/parser/functions/get_scope_args.rb Its still in a topic branch in my own personal clone and very much draft as I''ve been trying to find good ways to write spec tests for it. But it should do the trick. It returns a hash - which you could then convert to a yaml document if you like. ken. On Tue, Oct 25, 2011 at 11:25 PM, Alessandro Franceschi <al@lab42.it> wrote:> Dear all, > is there a way to access in a template to all the parameters that are > passed/defined in a class? > > I mean, something like: > file { "puppi_openssh": > path => "${settings::vardir}/puppi/openssh", > mode => "0640", > owner => "root", > group => "root", > ensure => present, > content => inline_template("<%= scope.to_yaml %>"), > } > > but instead of accessing to all the variables in the scope (as in > scope.to_yaml ) I want to show only the variables passed to a > parametrized class or a define (something like: openssh::*.to_yaml ) > > The point is to have a quick and generic way to pass Puppet knowledge > (the variables defined/used) about a class, to a local file, that can > be used in various interesting ways. > > If there''s no way to do that, does anyone find this worth a feature > request? > > Best, > Alessandro Franceschi > > -- > 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.
Alessandro Franceschi
2011-Oct-25 23:26 UTC
[Puppet Users] Re: How to access to all the parameters of a parametrized class or a define
Great Ken! I (strongly :-) suggest to place this function (in a generic class- agnostic shape) in the puppetlabs-stdlib Thank you Al On Oct 26, 1:10 am, Ken Barber <k...@puppetlabs.com> wrote:> Hi Al :-). > > I''ve been working on this for the kwalify module so I can validate the > inputs for a resource/class: > > https://github.com/kbarber/puppetlabs-kwalify/blob/ticket/10136-get_s... > > Its still in a topic branch in my own personal clone and very much > draft as I''ve been trying to find good ways to write spec tests for > it. But it should do the trick. > > It returns a hash - which you could then convert to a yaml document if you like. > > ken. > > > > > > > > On Tue, Oct 25, 2011 at 11:25 PM, Alessandro Franceschi <a...@lab42.it> wrote: > > Dear all, > > is there a way to access in a template to all the parameters that are > > passed/defined in a class? > > > I mean, something like: > > file { "puppi_openssh": > > path => "${settings::vardir}/puppi/openssh", > > mode => "0640", > > owner => "root", > > group => "root", > > ensure => present, > > content => inline_template("<%= scope.to_yaml %>"), > > } > > > but instead of accessing to all the variables in the scope (as in > > scope.to_yaml ) I want to show only the variables passed to a > > parametrized class or a define (something like: openssh::*.to_yaml ) > > > The point is to have a quick and generic way to pass Puppet knowledge > > (the variables defined/used) about a class, to a local file, that can > > be used in various interesting ways. > > > If there''s no way to do that, does anyone find this worth a feature > > request? > > > Best, > > Alessandro Franceschi > > > -- > > 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.
Ken Barber
2011-Oct-25 23:37 UTC
Re: [Puppet Users] Re: How to access to all the parameters of a parametrized class or a define
Well perhaps I might :-). Its still in development at the moment - once I can this tested and merged into puppetlabs-kwalify we''ll see what happens. Its a nice multi-purpose function that is for sure :-). I wrote it this way decoupled from the original kwalify validate_resource function for this specific reason - its a lighter re-usable touch. Let me know about any bugs - its not tested yet in the wild :-). ken. On Wed, Oct 26, 2011 at 12:26 AM, Alessandro Franceschi <al@lab42.it> wrote:> Great Ken! > I (strongly :-) suggest to place this function (in a generic class- > agnostic shape) in the puppetlabs-stdlib > > Thank you > Al > > On Oct 26, 1:10 am, Ken Barber <k...@puppetlabs.com> wrote: >> Hi Al :-). >> >> I''ve been working on this for the kwalify module so I can validate the >> inputs for a resource/class: >> >> https://github.com/kbarber/puppetlabs-kwalify/blob/ticket/10136-get_s... >> >> Its still in a topic branch in my own personal clone and very much >> draft as I''ve been trying to find good ways to write spec tests for >> it. But it should do the trick. >> >> It returns a hash - which you could then convert to a yaml document if you like. >> >> ken. >> >> >> >> >> >> >> >> On Tue, Oct 25, 2011 at 11:25 PM, Alessandro Franceschi <a...@lab42.it> wrote: >> > Dear all, >> > is there a way to access in a template to all the parameters that are >> > passed/defined in a class? >> >> > I mean, something like: >> > file { "puppi_openssh": >> > path => "${settings::vardir}/puppi/openssh", >> > mode => "0640", >> > owner => "root", >> > group => "root", >> > ensure => present, >> > content => inline_template("<%= scope.to_yaml %>"), >> > } >> >> > but instead of accessing to all the variables in the scope (as in >> > scope.to_yaml ) I want to show only the variables passed to a >> > parametrized class or a define (something like: openssh::*.to_yaml ) >> >> > The point is to have a quick and generic way to pass Puppet knowledge >> > (the variables defined/used) about a class, to a local file, that can >> > be used in various interesting ways. >> >> > If there''s no way to do that, does anyone find this worth a feature >> > request? >> >> > Best, >> > Alessandro Franceschi >> >> > -- >> > 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.