forked from garethr/garethr-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.pp
51 lines (44 loc) · 1.21 KB
/
exec.pp
1
2
3
4
5
6
7
8
9
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
#
# A define which executes a command inside a container.
#
define docker::exec(
$detach = false,
$interactive = false,
$tty = false,
$container = undef,
$command = undef,
$unless = undef,
$sanitise_name = true,
) {
include docker::params
$docker_command = $docker::params::docker_command
validate_string($docker_command)
validate_string($container)
validate_string($command)
validate_string($unless)
validate_bool($detach)
validate_bool($interactive)
validate_bool($tty)
$docker_exec_flags = docker_exec_flags({
detach => $detach,
interactive => $interactive,
tty => $tty,
})
if $sanitise_name {
$sanitised_container = regsubst($container, '[^0-9A-Za-z.\-_]', '-', 'G')
} else {
$sanitised_container = $container
}
$exec = "${docker_command} exec ${docker_exec_flags} ${sanitised_container} ${command}"
$unless_command = $unless ? {
undef => undef,
'' => undef,
default => "${docker_command} exec ${docker_exec_flags} ${sanitised_container} ${$unless}",
}
exec { $exec:
environment => 'HOME=/root',
path => ['/bin', '/usr/bin'],
timeout => 0,
unless => $unless_command,
}
}