Puppet Function: extlib::mkdir_p

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

Summary

Like the unix command mkdir_p except with puppet code.

Overview

extlib::mkdir_p(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] $dirs)Array[Stdlib::Absolutepath]

This creates file resources for all directories and utilizes the dir_split() function to get a list of all the descendant directories. You will have no control over any other parameters for the file resource. If you wish to control the file resources you can use the dir_split() function and get an array of directories for use in your own code. Please note this does not use an exec resource.

Note:

splits the given directories into paths that are then created using file resources

Note:

if you wish to create the directories manually you can use the extlib::dir_split() function in the same manner

Examples:

How to use

extlib::mkdir_p('/opt/puppetlabs/bin') => ['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin']

Parameters:

  • dirs (Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]])
    • the path(s) to create

Returns:

  • (Array[Stdlib::Absolutepath])


13
14
15
16
17
18
19
20
21
22
# File 'functions/mkdir_p.pp', line 13

function extlib::mkdir_p(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] *$dirs) >> Array[Stdlib::Absolutepath] {
  $dirs_array = $dirs.flatten.unique.map |$dir| {
    extlib::dir_split($dir)
  }.flatten.unique.sort
  @file { $dirs_array:
    ensure => directory,
  }
  realize(File[$dirs_array])
  $dirs_array
}