On Tuesday, November 20, 2012 8:42:02 AM UTC-6, KomodoDave wrote:
>
> I'm trying to use my first custom function *prefixPaths*.
>
> The function is defined in:
>
> my_module/lib/puppet/parser/functions/prefixPaths.rb
>
>
> Listing:
>
> module Puppet::Parser::Functions
>     newfunction(:prefixPaths, :type => :rvalue) do |args|
>         args[1].map{|path| "#{args[0]}/#{path}"}
>     end
> end
>
>
> It's usage is e.g. *prefixPaths( 'base', [ 'A', 'path/to/B' ] ) => [ 
> 'base/A', 'base/path/to/B' ]*
> *
> *
> I'm trying to use it in a Puppet manifest when creating a set of 
> directories on the client:
>
>     $bashScriptDir  = "bash-scripts"
>     $karafScriptDir = "karaf-scripts"
>     $userTypeDir    = "user-type-resources"
>     $resourceDirs   = [$bashScriptDir,$karafScriptDir,$userTypeDir]
>     file { 'Create common dirs.':
>         path => $localPaths,
>         ensure => 'Directory'
>     }
>
> However, when I use this the following error results:
>
> err: Failed to apply catalog: Parameter path failed: File paths must be 
> fully qualified, not 
> '/fuse/common/bash-scripts/fuse/common/karaf-scripts/fuse/common/user-type-resources'
>  
> at /etc/puppet/gitmodules/app_fuse/manifests/init.pp:113
>
>
> It looks like it's flattening the array.
>
> I've seen another conversation on here indicating arrays are permitted to 
> be used as custom function return values.
>
> Would someone be kind enough to indicate what I'm doing wrong?
>
>

Well, you didn't show how the custom function is actually used there, but I 
guess you omitted a statement of the form

  $localPaths = prefixPaths('/fuse/common', $resourceDirs)

, right?

I suspect the problem is not with your function.  Most likely, the array is 
getting flattened after it is returned.  In fact, I'd be very surprised if 
the value you assign to your File's 'path' property were not flattened.  As 
far as I know, the ability to declare multiple, similar resources by using 
an array as the resource title requires the array to be the actual title.  
I don't think you get the same result by assigning an array to the 
resource's namevar (nor do I think you should).

So, try this:

# Manage common directories
file { $localPaths:
  ensure => 'directory'
}


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/bXeeTuswXKcJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to