Puppet Function: wmflib::dir::mkdir_p

Defined in:
modules/wmflib/functions/dir/mkdir_p.pp
Function type:
Puppet Language

Overview

wmflib::dir::mkdir_p(Variant[Stdlib::Unixpath, Array[Stdlib::Unixpath]] $dirs, Hash $params = {})Any

This creates file resources for all directories returned by wmflib::dir::split. you can also pass a parameteres hash of file resource paramters which will be applied to the target dirs

Examples:

creating directories

wmflib::dir::mkdir_p('/opt/puppetlabs/bin') will create:
file{['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin']: ensure => directory}

creating directories with additional properties

wmflib::dir::mkdir_p('/opt/puppetlabs/bin', {owner => 'foobar'}) will create:
file{['/opt', '/opt/puppetlabs']: ensure => directory}
file{['/opt', '/opt/puppetlabs']:
  ensure => directory,
owner  => 'foobar',
}

Parameters:

  • dirs (Variant[Stdlib::Unixpath, Array[Stdlib::Unixpath]])

    the path(s) to create

  • params (Hash) (defaults to: {})

    the resource parameters to apply to dirs

Returns:

  • (Any)


17
18
19
20
21
22
23
24
25
26
27
# File 'modules/wmflib/functions/dir/mkdir_p.pp', line 17

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)
}