vchepkov
08/04/2023, 5:04 PMMoe
08/04/2023, 5:04 PMvchepkov
08/04/2023, 5:06 PMvchepkov
08/04/2023, 5:06 PMreduce
, maybe that's what you need?Moe
08/04/2023, 5:07 PMjms1
08/04/2023, 6:39 PManchor
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?jms1
08/04/2023, 6:39 PMrnelson0
08/04/2023, 6:43 PMcontain
is probably what you're looking for now.rnelson0
08/04/2023, 6:45 PMcsharpsteen
08/04/2023, 6:45 PMSlackbot
08/04/2023, 6:47 PMSlackbot
08/04/2023, 6:48 PMSlackbot
08/04/2023, 6:49 PMSlackbot
08/04/2023, 7:42 PMMoe
08/04/2023, 8:05 PM/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?jms1
08/04/2023, 8:07 PMfile
resources for /foo
, /foo/bar
, and /foo/bar/baz
jms1
08/04/2023, 8:07 PMmkdir -p
does, automatically create any missing parent directories?Moe
08/04/2023, 8:07 PMjms1
08/04/2023, 8:12 PM$dir.split('/').reduce('') |$a,$n| {
file { "${a}${n}" :
ensure => directory ,
owner => 'root' ,
group => 'root' ,
mode => '0755' ,
}
"${a}${n}/"
}
jms1
08/04/2023, 8:13 PMreduce()
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 awesomejms1
08/04/2023, 8:15 PM$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?Moe
08/04/2023, 8:16 PMMoe
08/04/2023, 8:16 PMMoe
08/04/2023, 8:18 PMError: Evaluation Error: Empty string title at 0. Title strings must have a length greater than zero.
Moe
08/04/2023, 8:22 PMnatemccurdy
08/04/2023, 8:41 PM/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
.Moe
08/04/2023, 8:47 PMnatemccurdy
08/04/2023, 8:53 PMSlackbot
08/04/2023, 8:56 PMSlackbot
08/04/2023, 8:57 PM