FAQ
Hi all,

I'd like to specify a base_directory and a list of directories (as
variables that may be pulled via hiera later) that will be created under
that base directory.

base_dir = "/home/base"
bars = ["a", "b", "c"]

bars will be used to create the folders under base and also part of the
information going into building a template so I don't want to store them as
["$base_dir/a", "$base_dir/b", "$base_dir/c"].

What's the best way to create the bar directories under the base_dir? I'd
love to just give File the bars array and specify the base_dir as a
property. Should I make a prepend function that would prepend base_dir to
each bar and then pass that to File?

I tried a definition but then to loop I have to generate a single loop-able
structure to call the definition with that contains both bars and base_dir.
I looked at create_resources but that seems like it'd force me to make more
things variables than I wanted and duplicate more than I would like.

Thanks,
Mark

--
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/-/WFydQrjUbdQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Mark Roggenkamp at Jun 25, 2012 at 6:17 pm
    Actually, I think a definition will work.

    define file_with_base($base_dir) {
    file {"$base_dir/$name":
    ...
    }
    }

    file_with_base($bars:
    base_dir => $base_dir
    }

    I didn't think about the $name coming from an array used when creating the
    file_with_base definition. I was only thinking about the parameters
    specified in the define, which probably comes from me continuing to think
    of it like a function which is wrong.

    Regards
    Mark
    On Monday, June 25, 2012 1:27:40 PM UTC-4, Mark Roggenkamp wrote:

    Hi all,

    I'd like to specify a base_directory and a list of directories (as
    variables that may be pulled via hiera later) that will be created under
    that base directory.

    base_dir = "/home/base"
    bars = ["a", "b", "c"]

    bars will be used to create the folders under base and also part of the
    information going into building a template so I don't want to store them as
    ["$base_dir/a", "$base_dir/b", "$base_dir/c"].

    What's the best way to create the bar directories under the base_dir? I'd
    love to just give File the bars array and specify the base_dir as a
    property. Should I make a prepend function that would prepend base_dir to
    each bar and then pass that to File?

    I tried a definition but then to loop I have to generate a single
    loop-able structure to call the definition with that contains both bars and
    base_dir. I looked at create_resources but that seems like it'd force me to
    make more things variables than I wanted and duplicate more than I would
    like.

    Thanks,
    Mark
    --
    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/-/cPwQ82qQ594J.
    To post to this group, send email to [email protected].
    To unsubscribe from this group, send email to [email protected].
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Stefan Schulte at Jun 26, 2012 at 11:13 pm

    On Mon, Jun 25, 2012 at 10:27:40AM -0700, Mark Roggenkamp wrote:
    Hi all,

    I'd like to specify a base_directory and a list of directories (as
    variables that may be pulled via hiera later) that will be created under
    that base directory.

    base_dir = "/home/base"
    bars = ["a", "b", "c"]

    bars will be used to create the folders under base and also part of the
    information going into building a template so I don't want to store them as
    ["$base_dir/a", "$base_dir/b", "$base_dir/c"].

    What's the best way to create the bar directories under the base_dir? I'd
    love to just give File the bars array and specify the base_dir as a
    property. Should I make a prepend function that would prepend base_dir to
    each bar and then pass that to File?

    I tried a definition but then to loop I have to generate a single loop-able
    structure to call the definition with that contains both bars and base_dir.
    I looked at create_resources but that seems like it'd force me to make more
    things variables than I wanted and duplicate more than I would like.

    Thanks,
    Mark
    If you don't want to use a define here you can use the way how the regsubst
    function works on arrays: It will apply the substition on all elements and
    will then return an array with the same length. So this does also work:

    $base_dir = '/home/base'
    $bars = ['a', 'b', 'c']

    # prefix all bars with base_dir
    $dirs = regsubst($bars, '(.*)', "${base_dir}/\\1")

    file { $dirs:
    ensure => directory,
    }

    -Stefan

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to [email protected].
    To unsubscribe from this group, send email to [email protected].
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Mark Roggenkamp at Jun 27, 2012 at 12:24 pm
    Even better. Thank you, sir.

    Mark
    On Tuesday, June 26, 2012 7:17:34 PM UTC-4, Stefan Schulte wrote:
    On Mon, Jun 25, 2012 at 10:27:40AM -0700, Mark Roggenkamp wrote:
    Hi all,

    I'd like to specify a base_directory and a list of directories (as
    variables that may be pulled via hiera later) that will be created under
    that base directory.

    base_dir = "/home/base"
    bars = ["a", "b", "c"]

    bars will be used to create the folders under base and also part of the
    information going into building a template so I don't want to store them as
    ["$base_dir/a", "$base_dir/b", "$base_dir/c"].

    What's the best way to create the bar directories under the base_dir? I'd
    love to just give File the bars array and specify the base_dir as a
    property. Should I make a prepend function that would prepend base_dir to
    each bar and then pass that to File?

    I tried a definition but then to loop I have to generate a single loop-able
    structure to call the definition with that contains both bars and base_dir.
    I looked at create_resources but that seems like it'd force me to make more
    things variables than I wanted and duplicate more than I would like.

    Thanks,
    Mark
    If you don't want to use a define here you can use the way how the
    regsubst
    function works on arrays: It will apply the substition on all elements and
    will then return an array with the same length. So this does also work:

    $base_dir = '/home/base'
    $bars = ['a', 'b', 'c']

    # prefix all bars with base_dir
    $dirs = regsubst($bars, '(.*)', "${base_dir}/\\1")

    file { $dirs:
    ensure => directory,
    }

    -Stefan
    --
    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/-/HKsT2kp7CGQJ.
    To post to this group, send email to [email protected].
    To unsubscribe from this group, send email to [email protected].
    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
postedJun 25, '12 at 5:28p
activeJun 27, '12 at 12:24p
posts4
users2
websitepuppetlabs.com

2 users in discussion

Mark Roggenkamp: 3 posts Stefan Schulte: 1 post

People

Translate

site design / logo © 2023 Grokbase