FAQ
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?

I'm on Puppet version 2.7.6 .

Sincere thanks for your time.

--
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/-/oGz4QjGWNzgJ.
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.

Search Discussions

  • Jcbollinger at Nov 20, 2012 at 8:36 pm

    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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • KomodoDave at Nov 21, 2012 at 3:42 pm
    Thank you very much for this jcbollinger - the way you've described it
    makes perfect sense.

    Dave

    On Tuesday, November 20, 2012 8:36:46 PM UTC, jcbollinger wrote:


    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/-/3j35r9hxfYEJ.
    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.
  • KomodoDave at Nov 21, 2012 at 3:43 pm
    ..or should I say - *John*!

    On Tuesday, November 20, 2012 2:42:02 PM UTC, 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?

    I'm on Puppet version 2.7.6 .

    Sincere thanks for your time.
    --
    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/-/ZvV7-l2oH4wJ.
    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.
  • KomodoDave at Nov 21, 2012 at 4:40 pm
    In fact I've since realised that the documents state the 'path' parameter
    is the *namevar* for a file resource type.

    So what you've said is spot on.

    Thank you again.

    On Wednesday, November 21, 2012 3:43:01 PM UTC, KomodoDave wrote:

    ..or should I say - *John*!

    On Tuesday, November 20, 2012 2:42:02 PM UTC, 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?

    I'm on Puppet version 2.7.6 .

    Sincere thanks for your time.
    --
    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/-/Mvqv3oodZSwJ.
    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.
  • KomodoDave at Nov 21, 2012 at 4:48 pm
    Actually this is interesting: the 'path' parameter has a default value of
    the title. So if you don't specify the path yet specify an array for the
    title, I wonder what the internal logic is?

    Intriguing...

    On Wednesday, November 21, 2012 4:40:38 PM UTC, KomodoDave wrote:

    In fact I've since realised that the documents state the 'path' parameter
    is the *namevar* for a file resource type.

    So what you've said is spot on.

    Thank you again.

    On Wednesday, November 21, 2012 3:43:01 PM UTC, KomodoDave wrote:

    ..or should I say - *John*!

    On Tuesday, November 20, 2012 2:42:02 PM UTC, 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?

    I'm on Puppet version 2.7.6 .

    Sincere thanks for your time.
    --
    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/-/EYQsbGApncoJ.
    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.
  • Jcbollinger at Nov 26, 2012 at 2:38 pm

    On Wednesday, November 21, 2012 10:41:48 AM UTC-6, KomodoDave wrote:
    Actually this is interesting: the 'path' parameter has a default value of
    the title. So if you don't specify the path yet specify an array for the
    title, I wonder what the internal logic is?

    Intriguing...
    You are missing an important subtlety: when you use an array as a resource
    title, you are declaring not just one resource but several separate
    resources -- one for each array element, with the corresponding element as
    its title. Each resource gets the same values for the assigned parameters,
    and default values for all others. Thus, this declaration

    file { [ '/tmp/one', '/tmp/two']:
    ensure => 'file',
    mode => 0644
    }

    is exactly equivalent to these two

    file { '/tmp/one':
    ensure => 'file',
    mode => 0644
    }

    file { '/tmp/two':
    ensure => 'file',
    mode => 0644
    }

    . The array-style declaration is strictly shorthand. The default 'path'
    parameter for File['/tmp/one'] is '/tmp/one', and the default 'path'
    parameter for File['/tmp/two'] is '/tmp/two', regardless of which form you
    use to declare them.


    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/-/dZPPXgbICagJ.
    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.
  • KomodoDave at Nov 26, 2012 at 2:57 pm
    Excellent information there John. Thank you for taking time to explain so
    clearly.

    Dave

    On Monday, November 26, 2012 2:38:39 PM UTC, jcbollinger wrote:


    On Wednesday, November 21, 2012 10:41:48 AM UTC-6, KomodoDave wrote:

    Actually this is interesting: the 'path' parameter has a default value of
    the title. So if you don't specify the path yet specify an array for the
    title, I wonder what the internal logic is?

    Intriguing...
    You are missing an important subtlety: when you use an array as a resource
    title, you are declaring not just one resource but several separate
    resources -- one for each array element, with the corresponding element as
    its title. Each resource gets the same values for the assigned parameters,
    and default values for all others. Thus, this declaration

    file { [ '/tmp/one', '/tmp/two']:
    ensure => 'file',
    mode => 0644
    }

    is exactly equivalent to these two

    file { '/tmp/one':
    ensure => 'file',
    mode => 0644
    }

    file { '/tmp/two':
    ensure => 'file',
    mode => 0644
    }

    . The array-style declaration is strictly shorthand. The default 'path'
    parameter for File['/tmp/one'] is '/tmp/one', and the default 'path'
    parameter for File['/tmp/two'] is '/tmp/two', regardless of which form you
    use to declare them.


    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/-/Hbn43b2NsxsJ.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedNov 20, '12 at 4:23p
activeNov 26, '12 at 2:57p
posts8
users2
websitepuppetlabs.com

2 users in discussion

KomodoDave: 6 posts Jcbollinger: 2 posts

People

Translate

site design / logo © 2022 Grokbase