On Thu, May 3, 2012 at 4:27 AM, Josh <
jo...@chickenmonkey.co.uk> wrote:
> I have had a look around and cannot seem to find out whether this is
> possible. To explain further (using 2.7.13 btw)...
>
> I have
>
> a module that I am using to configure various things about the network, lets
> call it 'my_network'
> another module that defines my platform, for arguments sake 'my_webserver'
>
> Now, in the 'my_network' module I have a definedtype that generates
> /etc/network/interfaces from a given ERB template which is associated with
> the platform, simplified version:
>
> define my_network::interfaces ($template = $title) {
> file { '/etc/network/interfaces':
> ensure => present,
> content => template($template),
> }
> }
>
> I call this like so from 'my_webserver':
>
> my_network::interfaces { my_webserver/interfaces_template.erb: }
>
> This results in an error where it cannot see the template:
>
> err: Could not retrieve catalog from remote server: Error 400 on SERVER:
> Failed to parse template my_webserver/interfaces_template.erb: undefined
> method `[]' for nil:NilClass at
> /local/puppet/env/production/modules/my_network/manifests/interfaces.pp:47
> on node
mynode.com
Seems like puppet is invoking the correct template. The problem is
puppet failed to process the template.
A quick example with inline template:
$x = inline_template("<% var=nil %><%= var.[] %>")
Failed to parse inline template: undefined method `[]' for
nil:NilClass at /tmp/template.pp:1 on node raiden.home.lan
> I also tried this using Classes rather then definedtypes and had the same
> problem.
>
> What I want to do is have the function for handling network configuration in
> its own module (to avoid duplication of code and confusion) and the
> templates situated in another module specific to my node or platform.
>
> So is there any way that I can use a template from another module? From my
> understanding of how puppet compiles the catalogue I cannot see why it
> wouldn't work?
So in this case the template function tells you the error, but not the
line number, however you can get that info from the exception back
trace, so we can add that via Puppet.debug to
puppet/lib/puppet/parser/functions/template.rb:
rescue => detail
Puppet.debug(detail.backtrace.first)
raise Puppet::ParseError,
"Failed to parse template #{file}: #{detail}"
end
Now when we run it the template puppet debug gives the file
/tmp/example.erb and line number 10:
debug: /tmp/example.erb:10:in `result'
Failed to parse template /tmp/example.erb: undefined method `[]' for
nil:NilClass at /Users/nan/proj/tmp/invoke.pp:1 on node
raiden.home.lan
Maybe the file and line number should part of the error in the first
place. I've opened a ticket to sort out the best way we can improve
these things since it makes troubleshooting much easier:
http://projects.puppetlabs.com/issues/14296
Thanks,
Nan