10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'manifests/tools/create_dir.pp', line 10
define psick::tools::create_dir (
Optional[String] $owner = undef,
Optional[String] $group = undef,
Optional[Stdlib::Filemode] $mode = undef,
Stdlib::AbsolutePath $path = $title,
) {
$mkdir_command = $facts['os']['family'] ? {
'windows' => "New-Item -ItemType Directory -Force -Path '${path}'",
default => "mkdir -p '${path}'",
}
$command_provider = $facts['os']['family'] ? {
'windows' => 'powershell',
default => undef,
}
exec { "Create directory ${title}":
command => $mkdir_command,
path => $facts['path'],
creates => $path,
provider => $command_provider,
}
if $facts['os']['family'] != 'windows' {
if $owner {
exec { "chown ${owner} ${title}":
command => "chown '${owner}' '${path}'",
path => $facts['path'],
onlyif => "[ \$(stat -c '%U' '${path}') != '${owner}' ]",
}
}
if $group {
exec { "chgrp ${group} ${title}":
command => "chgrp '${group}' '${path}'",
path => $facts['path'],
onlyif => "[ \$(stat -c '%G' '${path}') != '${group}' ]",
}
}
if $mode {
$short_mode = regsubst($mode, '^0', '')
exec { "chmod ${mode} ${title}":
command => "chmod '${mode}' '${path}'",
path => '/bin:/sbin:/usr/sbin:/usr/bin',
onlyif => "[ \$(stat -c '%a' '${path}') != '${short_mode}' ]",
}
}
}
}
|