forked from puppetlabs/puppetlabs-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine.pp
114 lines (104 loc) · 3.76 KB
/
machine.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# == Class: docker::machine
#
# Class to install Docker Machine using the recommended curl command.
#
# === Parameters
#
# [*ensure*]
# Whether to install or remove Docker Machine
# Valid values are absent present
# Defaults to present
#
# [*version*]
# The version of Docker Machine to install.
# Defaults to the value set in $docker::params::machine_version
#
# [*install_path*]
# The path where to install Docker Machine.
# Defaults to the value set in $docker::params::machine_install_path
#
# [*proxy*]
# Proxy to use for downloading Docker Machine.
#
# [*url*]
# The URL from which the docker machine binary should be fetched
# Defaults to a auto determined value based on version, kernel and OS.
#
# [*curl_ensure*]
# Whether or not the curl package is ensured by this module.
# Defaults to true
class docker::machine(
Optional[Pattern[/^present$|^absent$/]] $ensure = 'present',
Optional[String] $version = $docker::params::machine_version,
Optional[String] $install_path = $docker::params::machine_install_path,
Optional[String] $proxy = undef,
Optional[Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]] $url = undef,
Optional[Boolean] $curl_ensure = $docker::params::curl_ensure,
) inherits docker::params {
if $proxy != undef {
validate_re($proxy, '^((http[s]?)?:\/\/)?([^:^@]+:[^:^@]+@|)([\da-z\.-]+)\.([\da-z\.]{2,6})(:[\d])?([\/\w \.-]*)*\/?$')
}
if $::osfamily == 'windows' {
$file_extension = '.exe'
$file_owner = 'Administrator'
} else {
$file_extension = ''
$file_owner = 'root'
}
$docker_machine_location = "${install_path}/docker-machine${file_extension}"
$docker_machine_location_versioned = "${install_path}/docker-machine-${version}${file_extension}"
if $ensure == 'present' {
$docker_machine_url = $url ? {
undef => "https://github.com/docker/machine/releases/download/v${version}/docker-machine-${::kernel}-x86_64${file_extension}",
default => $url,
}
if $proxy != undef {
$proxy_opt = "--proxy ${proxy}"
} else {
$proxy_opt = ''
}
if $::osfamily == 'windows' {
# lint:ignore:140chars
$docker_download_command = "if (Invoke-WebRequest ${docker_machine_url} ${proxy_opt} -UseBasicParsing -OutFile \"${docker_machine_location_versioned}\") { exit 0 } else { exit 1}"
# lint:endignore
exec { "Install Docker Machine ${version}":
command => template('docker/windows/download_docker_machine.ps1.erb'),
provider => powershell,
creates => $docker_machine_location_versioned,
}
file { $docker_machine_location:
ensure => 'link',
target => $docker_machine_location_versioned,
require => Exec["Install Docker Machine ${version}"]
}
} else {
if $curl_ensure {
ensure_packages(['curl'])
}
exec { "Install Docker Machine ${version}":
path => '/usr/bin/',
cwd => '/tmp',
command => "curl -s -S -L ${proxy_opt} ${docker_machine_url} -o ${docker_machine_location_versioned}",
creates => $docker_machine_location_versioned,
require => Package['curl'],
}
file { $docker_machine_location_versioned:
owner => $file_owner,
mode => '0755',
require => Exec["Install Docker Machine ${version}"]
}
file { $docker_machine_location:
ensure => 'link',
target => $docker_machine_location_versioned,
require => File[$docker_machine_location_versioned]
}
}
} else {
file { [
$docker_machine_location_versioned,
$docker_machine_location
]:
ensure => absent,
}
}
}