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
|
# File 'manifests/run.pp', line 1
define docker::run(
$ensure = "present",
$image = $title,
$containerName = undef,
$command = undef
) {
if $ensure == "present" {
if $containerName {
$findContainer = "docker ps | grep ${containerName}"
$runContainer = "/usr/bin/docker run --name ${containerName} -d ${image} ${command}"
exec { $runContainer:
path => ['/bin', '/usr/bin'],
unless => $findContainer
}
} else {
$findContainer = "docker ps | grep ${image}"
$runContainer = "/usr/bin/docker run -d ${image} ${command}"
exec { $runContainer:
path => ['/bin', '/usr/bin'],
unless => $findContainer
}
}
} else {
if $containerName {
$findContainer = "docker ps | grep ${containerName}"
$rm = "/usr/bin/docker rm -f ${containerName}"
exec { $rm:
path => ['/bin', '/usr/bin'],
onlyif => $findContainer,
timeout => 0,
}
} else {
$findContainer = "docker ps | grep ${image}"
$rm = "/usr/bin/docker rm -f $(docker ps | grep ${image} | awk {'print \$1'})"
exec { $rm:
path => ['/bin', '/usr/bin'],
onlyif => $findContainer,
timeout => 0,
}
}
}
}
|