Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for chocolatey v2 #247

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@
} # end OpenBSD

'Windows' : {
$cmd_install_dir = regsubst($filebeat::install_dir, '/', '\\', 'G')
$filebeat_path = join([$cmd_install_dir, 'Filebeat', 'filebeat.exe'], '\\')

$validate_cmd = ($filebeat::disable_config_test or $skip_validation) ? {
true => undef,
default => $major_version ? {
'7' => "\"${filebeat_path}\" test config -c \"%\"",
default => "\"${filebeat_path}\" -N -configtest -c \"%\"",
}
if $filebeat::chocolatey_provider {

$filebeat_path = 'C:\ProgramData\chocolatey\lib\filebeat\tools\filebeat.exe'

} else {

$cmd_install_dir = regsubst($filebeat::install_dir, '/', '\\', 'G')
$filebeat_path = join([$cmd_install_dir, 'Filebeat', 'filebeat.exe'], '\\')
}

file {'filebeat.yml':
Expand All @@ -211,6 +211,16 @@
require => File['filebeat-config-dir'],
}

$validate_cmd = ($filebeat::disable_config_test or $skip_validation) ? {
true => undef,
default => $major_version ? {
'7' => "\"${filebeat_path}\" test config -c \"%\"",
default => "\"${filebeat_path}\" -N -configtest -c \"%\"",
}
}



file {'filebeat-config-dir':
ensure => $filebeat::directory_ensure,
path => $filebeat::config_dir,
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
Optional[String] $systemd_beat_log_opts_override = undef,
String $systemd_beat_log_opts_template = $filebeat::params::systemd_beat_log_opts_template,
String $systemd_override_dir = $filebeat::params::systemd_override_dir,
Boolean $chocolatey_provider = false,
Optional[String[1]] $package_name = $filebeat::params::package_name,

) inherits filebeat::params {

Expand Down
126 changes: 68 additions & 58 deletions manifests/install/windows.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,83 @@
# that in the future as it would greatly simplify this code and basically reduce it to
# one package resource with type => chocolatey....

$filename = regsubst($filebeat::real_download_url, '^https?.*\/([^\/]+)\.[^.].*', '\1')
$foldername = 'Filebeat'
$zip_file = join([$filebeat::tmp_dir, "${filename}.zip"], '/')
$install_folder = join([$filebeat::install_dir, $foldername], '/')
$version_file = join([$install_folder, $filename], '/')

Exec {
provider => powershell,
if $filebeat::chocolatey_provider {
package { $filebeat::package_name:
ensure => $filebeat::chocolatey_package_ensure,
provider => 'chocolatey',
}
}
else {
$filename = regsubst($filebeat::real_download_url, '^https?.*\/([^\/]+)\.[^.].*', '\1')
$foldername = 'Filebeat'
$zip_file = join([$filebeat::tmp_dir, "${filename}.zip"], '/')
$install_folder = join([$filebeat::install_dir, $foldername], '/')
$version_file = join([$install_folder, $filename], '/')

if ! defined(File[$filebeat::install_dir]) {
file { $filebeat::install_dir:
ensure => directory,
Exec {
provider => powershell,
}
}

# Note: We can use archive for unzip and cleanup, thus removing the following two resources.
# However, this requires 7zip, which archive can install via chocolatey:
# https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31
# I'm not choosing to impose those dependencies on anyone at this time...
archive { $zip_file:
source => $filebeat::real_download_url,
cleanup => false,
creates => $version_file,
proxy_server => $filebeat::proxy_address,
}
if !defined(File[$filebeat::install_dir]) {
file { $filebeat::install_dir:
ensure => directory,
}
}

exec { "unzip ${filename}":
command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${filebeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars
creates => $version_file,
require => [
File[$filebeat::install_dir],
Archive[$zip_file],
],
}
# Note: We can use archive for unzip and cleanup, thus removing the following two resources.
# However, this requires 7zip, which archive can install via chocolatey:
# https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31
# I'm not choosing to impose those dependencies on anyone at this time...
archive { $zip_file:
source => $filebeat::real_download_url,
cleanup => false,
creates => $version_file,
proxy_server => $filebeat::proxy_address,
}

# Clean up after ourselves
file { $zip_file:
ensure => absent,
backup => false,
require => Exec["unzip ${filename}"],
}
exec { "unzip ${filename}":
command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${filebeat::install_dir}
')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars
creates => $version_file,
require => [
File[$filebeat::install_dir],
Archive[$zip_file],
],
}

# You can't remove the old dir while the service has files locked...
exec { "stop service ${filename}":
command => 'Set-Service -Name filebeat -Status Stopped',
creates => $version_file,
onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'filebeat\'") {exit 0} else {exit 1}',
require => Exec["unzip ${filename}"],
}
# Clean up after ourselves
file { $zip_file:
ensure => absent,
backup => false,
require => Exec["unzip ${filename}"],
}

exec { "rename ${filename}":
command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${filebeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars
creates => $version_file,
require => Exec["stop service ${filename}"],
}
# You can't remove the old dir while the service has files locked...
exec { "stop service ${filename}":
command => 'Set-Service -Name filebeat -Status Stopped',
creates => $version_file,
onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'filebeat\'") {exit 0} else {exit 1}',
require => Exec["unzip ${filename}"],
}

exec { "mark ${filename}":
command => "New-Item '${version_file}' -ItemType file",
creates => $version_file,
require => Exec["rename ${filename}"],
}
exec { "rename ${filename}":
command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${
filebeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars
creates => $version_file,
require => Exec["stop service ${filename}"],
}

exec { "mark ${filename}":
command => "New-Item '${version_file}' -ItemType file",
creates => $version_file,
require => Exec["rename ${filename}"],
}

exec { "install ${filename}":
cwd => $install_folder,
command => './install-service-filebeat.ps1',
refreshonly => true,
subscribe => Exec["mark ${filename}"],
exec { "install ${filename}":
cwd => $install_folder,
command => './install-service-filebeat.ps1',
refreshonly => true,
subscribe => Exec["mark ${filename}"],
}
}
}
21 changes: 15 additions & 6 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
$xpack = undef
$systemd_override_dir = '/etc/systemd/system/filebeat.service.d'
$systemd_beat_log_opts_template = "${module_name}/systemd/logging.conf.erb"

$package_name = 'filebeat'
$chocolatey_basedir = "C:/ProgramData/chocolatey/lib/filebeat/tools"
# These are irrelevant as long as the template is set based on the major_version parameter
# if versioncmp('1.9.1', $::rubyversion) > 0 {
# $conf_template = "${module_name}/filebeat.yml.ruby18.erb"
Expand Down Expand Up @@ -123,15 +124,23 @@
}

'Windows' : {
$package_ensure = '7.1.0'
$path_exists = find_file($chocolatey_basedir)
if $path_exists {
$config_file = 'C:/ProgramData/chocolatey/lib/filebeat/tools/filebeat.yml'
$modules_dir = 'C:/ProgramData/chocolatey/lib/filebeat/tools/modules.d'
$config_dir = 'C:/ProgramData/chocolatey/lib/filebeat/tools/conf.d'
} else {
$config_file = 'C:/Program Files/Filebeat/filebeat.yml'
$modules_dir = 'C:/Program Files/Filebeat/modules.d'
$config_dir = 'C:/Program Files/Filebeat/conf.d'
}
$install_dir = 'C:/Program Files'
$package_ensure = '7.1.0'
$config_file_owner = 'Administrator'
$config_file_group = undef
$config_dir_owner = 'Administrator'
$config_dir_group = undef
$config_file = 'C:/Program Files/Filebeat/filebeat.yml'
$config_dir = 'C:/Program Files/Filebeat/conf.d'
$modules_dir = 'C:/Program Files/Filebeat/modules.d'
$install_dir = 'C:/Program Files'

$tmp_dir = 'C:/Windows/Temp'
$service_provider = undef
$url_arch = $::architecture ? {
Expand Down