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
|
# File 'manifests/windows.pp', line 6
class datadog_agent::windows(
Integer $agent_major_version = $datadog_agent::params::default_agent_major_version,
String $agent_version = $datadog_agent::params::agent_version,
Optional[String] $agent_repo_uri = undef,
String $msi_location = 'C:/Windows/temp',
String $api_key = $datadog_agent::api_key,
String $hostname = $datadog_agent::host,
Array $tags = $datadog_agent::tags,
Enum['present', 'absent'] $ensure = 'present',
) inherits datadog_agent::params {
$msi_full_path = "${msi_location}/datadog-agent-${agent_major_version}-${agent_version}.amd64.msi"
if ($agent_repo_uri != undef) {
$baseurl = $agent_repo_uri
} else {
$baseurl = 'https://s3.amazonaws.com/ddagent-windows-stable/'
}
if $agent_version == 'latest' {
$msi_source = "${baseurl}datadog-agent-${agent_major_version}-latest.amd64.msi"
} else {
$msi_source = "${baseurl}ddagent-cli-${agent_version}.msi"
}
if $ensure == 'present' {
if ($agent_version in ['6.14.0', '6.14.1']) {
fail('The specified agent version has been blacklisted, please specify a version other than 6.14.0 or 6.14.1')
}
file { 'installer':
path => $msi_full_path,
source => $msi_source,
provider => 'windows',
}
exec { 'validate':
command => "\$blacklist = '928b00d2f952219732cda9ae0515351b15f9b9c1ea1d546738f9dc0fda70c336','78b2bb2b231bcc185eb73dd367bfb6cb8a5d45ba93a46a7890fd607dc9188194';\$fileStream = [system.io.file]::openread('${msi_full_path}'); \$hasher = [System.Security.Cryptography.HashAlgorithm]::create('sha256'); \$hash = \$hasher.ComputeHash(\$fileStream); \$fileStream.close(); \$fileStream.dispose();\$hexhash = [system.bitconverter]::tostring(\$hash).ToLower().replace('-','');if (\$blacklist.Contains(\$hexhash)) { Exit 1 }",
provider => 'powershell',
logoutput => 'on_failure',
require => File['installer'],
notify => Package[$datadog_agent::params::package_name]
}
if $agent_version == 'latest' {
$ensure_version = 'installed'
} else {
$ensure_version = $agent_version
}
package { $datadog_agent::params::package_name:
ensure => $ensure_version,
provider => 'windows',
source => $msi_full_path,
install_options => ['/norestart', {'APIKEY' => $api_key, 'HOSTNAME' => $hostname, 'TAGS' => $tags}]
}
} else {
exec { 'datadog_6_14_fix':
command => "((New-Object System.Net.WebClient).DownloadFile('https://s3.amazonaws.com/ddagent-windows-stable/scripts/fix_6_14.ps1', \$env:temp + '\\fix_6_14.ps1')); &\$env:temp\\fix_6_14.ps1",
provider => 'powershell',
}
package { $datadog_agent::params::package_name:
ensure => absent,
provider => 'windows',
uninstall_options => ['/quiet'],
subscribe => Exec['datadog_6_14_fix'],
}
}
}
|