You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The mkdir_p function can be quite useful but it doesn't take much to make it unusable in the catalog due to double resource definitions. I basically recreated mkdir_p as a defined resource before finding extlib and solved this issue by adding a filter to the resulting array. Add:
.filter|$_dir| {!defined(File[$_dir])} # filter out File resources already defined in the catalog
function wmflib::dir::mkdir_p(
Variant[Stdlib::Unixpath, Array[Stdlib::Unixpath]] $dirs,
Hash $params = {},
) {
$_dirs = wmflib::dir::normalise($dirs)
$parents = wmflib::dir::split($_dirs) - $_dirs
# ensure all parent directories exist
ensure_resource('file', $parents, {'ensure' => 'directory'})
# Apply params only to the actual directories
ensure_resource('file', $dirs, {'ensure' => 'directory'} + $params)
}
# usage
wmflib::dir::mkdir_p('/usr/local/share/foobar/www', {'owner' => 'www', 'mode' => '0700'})
Im personally not a fan of using defined due to its reliance on parse order, however it would be good to agree a way forward for this function and send it to stdlib
This thing also exists. https://forge.puppet.com/modules/pltraining/dirtree. Seems there are a lot of people with the same desires and a lot of homebrew solutions. I don't know what the best way to solve this is.
The mkdir_p function can be quite useful but it doesn't take much to make it unusable in the catalog due to double resource definitions. I basically recreated mkdir_p as a defined resource before finding extlib and solved this issue by adding a filter to the resulting array. Add:
to
puppet-extlib/functions/mkdir_p.pp
Line 16 in 37b738b
I've tested it and it works, it filters out already elsewhere defined resources (in my case some root directories which are created as mount points).
The text was updated successfully, but these errors were encountered: