Hi Puppet-People I''m playing around with writing a custom resource type for managing my Apache configs and I would like to use templates. I happened across Puppet::Util::ResourceTemplate, which seems to do the tricky stuff but the bit I''m struggling with is getting the template across from the puppet server to the puppet client. I have a module with these files: config/puppet/modules/eec-mike/manifests/init.pp config/puppet/modules/eec-mike/templates/mikeapache.erb config/puppet/modules/eec-mike/lib/puppet/type/mike_apache.rb My ''mike_apache'' type is defined in mike_apache.rb and through the magic of pluginsync, this file is transported to the client and run at the appropriate time. When I call Puppet::Util::ResourceTemplate.new(), I need to pass it the pathname of the template. No matter what I give it, it dies with a "Template ... does not exist" exception. It would appear that if I refer to the template from a .pp file I would do something like: content => template("eec-mike/mikeapache.erb") and somehow Puppet would work out that it needed to sync the mikeapache.erb file from the eec-mike/templates directory on the server. That seems to be the bit that''s missing when I refer to a template from the Ruby code implementing a custom type. Am I venturing into uncharted territory or am I missing some obvious way of getting the module templates directory synced across to the client? Cheers Grant -- 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 Feb 17, 10:07 pm, Grant McLean <gr...@mclean.net.nz> wrote:> It would appear that if I refer to the template from a .pp file I would > do something like: > > content => template("eec-mike/mikeapache.erb")Yes.> and somehow Puppet would work out that it needed to sync the > mikeapache.erb file from the eec-mike/templates directory on the server.No. template() is a Puppet function, and like all Puppet functions, it is evaluated by the Puppetmaster. It therefore does not sync the erb file with clients, and it does not have any access to the client system. Your custom resource may sync the resulting value, however, without regard to how the value was generated. 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.
On Feb 17, 10:07 pm, Grant McLean <gr...@mclean.net.nz> wrote:> I''m playing around with writing a custom resource type for managing my > Apache configs and I would like to use templates.Are you sure you need a custom resource type? It might be easier and more maintainable to use a Puppet define wrapped around one or more File resources, especially if you''re going to use templates to generate the content. 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.
Peter Meier
2010-Feb-18 14:36 UTC
Re: [Puppet Users] Re: Using templates from a custom type
> On Feb 17, 10:07 pm, Grant McLean <gr...@mclean.net.nz> wrote: >> I''m playing around with writing a custom resource type for managing my >> Apache configs and I would like to use templates. > > Are you sure you need a custom resource type? It might be easier and > more maintainable to use a Puppet define wrapped around one or more > File resources, especially if you''re going to use templates to > generate the content.the apache module @ [1] has different kinds of defines to create vhost entries. Most of them follow certain conventions so that defining a standard vhost is really only a bunch of lines, whoever you''re able to tweak nearly each aspect of a vhost. It is used and known to run on CentOS and debian hosts. cheers pete [1] http://git.puppet.immerda.ch/?p=module-apache.git;a=summary -- 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.
Grant McLean
2010-Feb-18 20:27 UTC
Re: [Puppet Users] Re: Using templates from a custom type
On Thu, 2010-02-18 at 05:53 -0800, jcbollinger wrote:> On Feb 17, 10:07 pm, Grant McLean <gr...@mclean.net.nz> wrote: > > It would appear that if I refer to the template from a .pp file I would > > do something like: > > > > content => template("eec-mike/mikeapache.erb") > > Yes. > > > and somehow Puppet would work out that it needed to sync the > > mikeapache.erb file from the eec-mike/templates directory on the server. > > No. template() is a Puppet function, and like all Puppet functions, > it is evaluated by the Puppetmaster. It therefore does not sync the > erb file with clients, and it does not have any access to the client > system. Your custom resource may sync the resulting value, however, > without regard to how the value was generated.Thank you very much for that explanation John. In hindsight, it probably should have been obvious. I''ll go back and rework my plans. Thanks Grant -- 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.
Grant McLean
2010-Feb-18 20:51 UTC
Re: [Puppet Users] Re: Using templates from a custom type
On Thu, 2010-02-18 at 15:36 +0100, Peter Meier wrote:> On Thu, 2010-02-18 at 05:59 -0800, jcbollinger wrote: > >On Feb 17, 10:07 pm, Grant McLean <gr...@mclean.net.nz> wrote: > > > I''m playing around with writing a custom resource type for managing my > > > Apache configs and I would like to use templates. > > > > Are you sure you need a custom resource type? It might be easier and > > more maintainable to use a Puppet define wrapped around one or more > > File resources, especially if you''re going to use templates to > > generate the content.Actually, I''m quite sure I don''t *need* to use a custom resource type. I am able to implement a solution with define+File resources, but I wanted to try using a custom resource in order to reduce the amount of boilerplate and repetition in my defines. The result was much more concise.> the apache module @ [1] has different kinds of defines to create vhost > entries. Most of them follow certain conventions so that defining a > standard vhost is really only a bunch of lines, whoever you''re able to > tweak nearly each aspect of a vhost.That seems to address a different use case to my situation. In my current project very few of the Apache instances use vhosts. We use the template to generate a complete config file for an Apache server which is dedicated to performing one particular role in the application. Having all the roles generated out of a single template has proven to vastly simplify the management. Thanks Grant -- 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.