Hi, Is it possible to pass parameters to use in templates? Or do you just set "global" variables in the class and then reference that in the template? Thanks, -matt zagrabelny -- 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.
On Mon, Oct 17, 2011 at 2:58 PM, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:> Hi, > > Is it possible to pass parameters to use in templates?Template function does not support parameters, just an array of erb templates.> Or do you just set "global" variables in the class and then reference > that in the template?You can access any variable in the scope the template function is invoked or use scope.lookupvar to be more explicit. See: http://docs.puppetlabs.com/guides/templating.html Thanks, 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.
To be a little more explicit about what Nan said, if you use a parameterized class, any parameters you passed into the class will also be available in the template. The same things goes for a define. On Oct 17, 5:58 pm, Matt Zagrabelny <mzagr...@d.umn.edu> wrote:> Hi, > > Is it possible to pass parameters to use in templates? > > Or do you just set "global" variables in the class and then reference > that in the template? > > Thanks, > > -matt zagrabelny-- 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.
Matt Zagrabelny
2011-Oct-18 17:24 UTC
Re: [Puppet Users] Re: passing parameters to templates
On Tue, Oct 18, 2011 at 12:11 PM, Steve Snodgrass <pheran@gmail.com> wrote:> To be a little more explicit about what Nan said, if you use a > parameterized class, any parameters you passed into the class will > also be available in the template. The same things goes for a define.I''ve got a class: class libapache2_mod_shib2::config($environment = "production") { if ($environment == "production") { $idp_server = "idp2.shib.umn.edu" $metadata_provider = "UofM-IDP-metadata.xml" } elsif ($environment == "testing") { $idp_server = "idp-test.shib.umn.edu" $metadata_provider = "UofM-IDP-test-metadata.xml" } else { fail("ensure parameter must be production or testing") } file { "/etc/shibboleth/shibboleth2.xml": owner => "root", group => "root", mode => 0644, content => template("libapache2_mod_shib2/etc/shibboleth/shibboleth2.xml.erb"), require => Class["libapache2_mod_shib2::install"], notify => Service["shibd"], } } In the template it seems that: $libapache2_mod_shib2::config::environment didn''t work. However, scope.lookupvar(''libapache2_mod_shib2::config::envirnoment'') did. Should the former mechanism work? Thanks, -mz -- 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.
On Tue, Oct 18, 2011 at 10:24 AM, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:> On Tue, Oct 18, 2011 at 12:11 PM, Steve Snodgrass <pheran@gmail.com> wrote: >> To be a little more explicit about what Nan said, if you use a >> parameterized class, any parameters you passed into the class will >> also be available in the template. The same things goes for a define. > > I''ve got a class: > > class libapache2_mod_shib2::config($environment = "production") { > if ($environment == "production") { > $idp_server = "idp2.shib.umn.edu" > $metadata_provider = "UofM-IDP-metadata.xml" > } elsif ($environment == "testing") { > $idp_server = "idp-test.shib.umn.edu" > $metadata_provider = "UofM-IDP-test-metadata.xml" > } else { > fail("ensure parameter must be production or testing") > } > > file { "/etc/shibboleth/shibboleth2.xml": > owner => "root", > group => "root", > mode => 0644, > content => template("libapache2_mod_shib2/etc/shibboleth/shibboleth2.xml.erb"), > require => Class["libapache2_mod_shib2::install"], > notify => Service["shibd"], > } > } > > In the template it seems that: > > $libapache2_mod_shib2::config::environment > > didn''t work. However, > > scope.lookupvar(''libapache2_mod_shib2::config::envirnoment'') > > did. > > Should the former mechanism work?No, templates variables are not the same as puppet variable. It will only support environment (no $, and no namespace ::). 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.