https://www.puppet.com/community logo
Join Slack
Powered by
# puppet
  • v

    vchepkov

    08/04/2023, 5:04 PM
    I don't see an array?
  • m

    Moe

    08/04/2023, 5:04 PM
    Whoops forget a line - again this was just for simplicity
  • v

    vchepkov

    08/04/2023, 5:06 PM
    You can't modify a variable, but you should be able to create a new one
  • v

    vchepkov

    08/04/2023, 5:06 PM
    look into
    reduce
    , maybe that's what you need?
  • m

    Moe

    08/04/2023, 5:07 PM
    Ah yes the example looks very promising! Thanks. Will check it out later tonight
  • j

    jms1

    08/04/2023, 6:39 PM
    at one point in the past i remember reading that
    anchor
    resources existed, but they didn't seem to be documented very well. they just solved a sticky problem for me (with PE 2016.2 aka puppet 4.5.2), however if something changes and i am finally given the time to bring our code base kicking and screaming into the modern age ... do
    anchor
    resources still exist in the current versions of puppet?
  • j

    jms1

    08/04/2023, 6:39 PM
    i want to be sure i didn't just create a problem for my future self
  • r

    rnelson0

    08/04/2023, 6:43 PM
    Yes, but for compatibility only. https://www.puppet.com/docs/puppet/8/lang_containment.html and https://www.puppet.com/docs/puppet/8/lang_relationships.html#lang_relationships are the relevant documents,
    contain
    is probably what you're looking for now.
  • r

    rnelson0

    08/04/2023, 6:45 PM
    aside: i love google searches for puppet, always amusing results πŸ˜„
  • c

    csharpsteen

    08/04/2023, 6:45 PM
    Anchor is part of stdlib and really hasn't had a meaningful non-documentation change since it was added 12 years ago: https://github.com/puppetlabs/puppetlabs-stdlib/commits/main/lib/puppet/type/anchor.rb So, it's as close to zero-maintenance overhead as a type could get. Removing it would cause a bunch of disruption in return for "savings" that essentially rounds to zero.
  • s

    Slackbot

    08/04/2023, 6:47 PM
    This message was deleted.
    b
    j
    +2
    • 5
    • 18
  • s

    Slackbot

    08/04/2023, 6:48 PM
    This message was deleted.
    r
    j
    • 3
    • 3
  • s

    Slackbot

    08/04/2023, 6:49 PM
    This message was deleted.
    d
    j
    • 3
    • 4
  • s

    Slackbot

    08/04/2023, 7:42 PM
    This message was deleted.
    b
    y
    d
    • 4
    • 12
  • m

    Moe

    08/04/2023, 8:05 PM
    Ok maybe I need to ask differently to get where I want to. I want to recursively check and create directories. So for a path of
    /foo/bar/baz
    I want to check whether
    /foo
    exists and if not create it and the same for all the other directories on that path. May idea was to use use the slice function and seperate the string by
    /
    and then do .each on each entry in the array that is created by the slice function. Now I tried
    recude
    but I either couldn't get the syntax right or this isn't what I'm looking for. Any ideas?
  • j

    jms1

    08/04/2023, 8:07 PM
    i would just declare
    file
    resources for
    /foo
    ,
    /foo/bar
    , and
    /foo/bar/baz
  • j

    jms1

    08/04/2023, 8:07 PM
    or are you starting with the full path and want to simulate what
    mkdir -p
    does, automatically create any missing parent directories?
    πŸ‘ 1
  • m

    Moe

    08/04/2023, 8:07 PM
    Yup, basically that. The path is a variable and so I need to be able to go to any depth.
  • j

    jms1

    08/04/2023, 8:12 PM
    ah ... maybe something like this: (this is absolutely not tested)
    Copy code
    $dir.split('/').reduce('') |$a,$n| {
        file { "${a}${n}" :
          ensure => directory ,
          owner  => 'root' ,
          group  => 'root' ,
          mode   => '0755' ,
        }
    
        "${a}${n}/"
      }
  • j

    jms1

    08/04/2023, 8:13 PM
    reduce()
    is kind of a weird function to wrap your head around if you haven't seen it before, but once it "clicks" it's pretty awesome
  • j

    jms1

    08/04/2023, 8:15 PM
    one thing to watch out for, if the first character of
    $dir
    is a
    /
    , the
    split()
    will return an empty string as the first element, so the first iteration of
    reduce()
    would end up declaring an empty string as the filename, which might be ... less than ideal?
    πŸ‘€ 1
  • m

    Moe

    08/04/2023, 8:16 PM
    Yes I keep reading the docs over and over and try to build small examples but it hasn't clicked so far. But I will get there eventually πŸ˜„
  • m

    Moe

    08/04/2023, 8:16 PM
    Let me test this out
  • m

    Moe

    08/04/2023, 8:18 PM
    You were right heh
    Error: Evaluation Error: Empty string title at 0. Title strings must have a length greater than zero.
  • m

    Moe

    08/04/2023, 8:22 PM
    Somehow I keep hitting this (see screenshot). I have tried various syntax but that's always where I end up sigh
  • n

    natemccurdy

    08/04/2023, 8:41 PM
    @Moe What you also need to watch out for... and why this is usually a bad practice and is not recommended.... is: a) having puppet manage paths like
    /foo
    . Top level directories that don't necessarily belong to the things inside of it. For example
    /etc
    or
    /opt
    . b) duplicate resource declarations for all of the parent directories. c) improper permissions (owner, group, mode) for parent directories. C in particular is why Puppet doesn't implement a
    mkdir -p
    pattern. It's too ambiguous and unclear, which is bad/dangerous when using Puppet. Best practice in this case is to just explicitly create
    file
    resources for the directories you care about. A quick "i don't really care about the security implications of not defining permissions on parent directories" solution is to use an
    exec
    that calls
    mkdir -p
    .
  • m

    Moe

    08/04/2023, 8:47 PM
    edit: I have thought about it more and you are right. I have to keep thinking about this more and go another route.
  • n

    natemccurdy

    08/04/2023, 8:53 PM
    The https://forge.puppet.com/modules/AlexCline/dirtree module helps with this.
    πŸ‘€ 1
  • s

    Slackbot

    08/04/2023, 8:56 PM
    This message was deleted.
    n
    b
    +2
    • 5
    • 9
  • s

    Slackbot

    08/04/2023, 8:57 PM
    This message was deleted.
    n
    m
    y
    • 4
    • 12
1...403404405...428Latest