Skip to content
Open
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
27 changes: 27 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ The following parameters are available in the `promtail` class:
* [`password_file_path`](#password_file_path)
* [`password_file_content`](#password_file_content)
* [`source_url`](#source_url)
* [`install_method`](#install_method)
* [`package_ensure`](#package_ensure)
* [`package_name`](#package_name)

##### <a name="service_enable"></a>`service_enable`

Expand Down Expand Up @@ -228,6 +231,30 @@ The URL from which promtail packages can be downloaded

Default value: `'https://github.com/grafana/loki/releases/download'`

##### <a name="install_method"></a>`install_method`

Data type: `Enum['package', 'archive']`

The way how promtail shall be installed, supported are archive (binary from GitHub) or package from an existing repo

Default value: `'archive'`

##### <a name="package_ensure"></a>`package_ensure`

Data type: `Enum['installed', 'absent']`

The desired ensure state of the package. Only used if `$install_method` is set to `package`

Default value: `'installed'`

##### <a name="package_name"></a>`package_name`

Data type: `String[1]`

The name of the package. Only used if `$install_method` is set to `package`

Default value: `'promtail'`

## Functions

### <a name="promtailstrip_yaml_header"></a>`promtail::strip_yaml_header`
Expand Down
11 changes: 10 additions & 1 deletion files/promtail.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ Documentation=https://github.com/grafana/loki/tree/master/docs/clients/promtail
After=network.target

[Service]
ExecStart=/usr/local/bin/promtail -config.file=/etc/promtail/config.yaml
Type=simple
User=root
Group=root
ExecStart=/usr/bin/promtail -config.file /etc/promtail/config.yml -config.expand-env=true
ExecReload=/bin/kill -HUP $MAINPID
TimeoutSec = 60
Restart=on-failure
RestartForceExitStatus=SIGPIPE
RestartSec = 2
KillMode=control-group

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=promtail

[Install]
WantedBy=multi-user.target
13 changes: 11 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ensure => directory,
}

$config_file = "${config_dir}/config.yaml"
$config_file = "${config_dir}/config.yml"

concat { $config_file:
ensure => present,
Expand Down Expand Up @@ -77,9 +77,18 @@
if $promtail::password_file_path and $promtail::password_file_content {
file { $promtail::password_file_path:
ensure => file,
mode => '0600',
mode => '0644',
content => unwrap($promtail::password_file_content),
show_diff => false,
}
}

if $promtail::password_app_file_path and $promtail::password_app_file_content {
file { $promtail::password_app_file_path:
ensure => file,
mode => '0644',
content => unwrap($promtail::password_app_file_content),
show_diff => false,
}
}
}
44 changes: 29 additions & 15 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# Note: each platform has its own checksum.
# Values can be found with each release on GitHub
#
# @param [String[1]] version
# @param [String[1]] binaryversion
# The version as listed on the GitHub release page
# See https://github.com/grafana/loki/releases for a list
#
Expand All @@ -60,6 +60,14 @@
# @param [Stdlib::HTTPUrl] source_url
# The URL from which promtail packages can be downloaded
#
# @param install_method
# The way how promtail shall be installed, supported are archive (binary from GitHub) or package from an existing repo
#
# @param package_ensure
# The desired ensure state of the package. Only used if `$install_method` is set to `package`
#
# @param package_name
# The name of the package. Only used if `$install_method` is set to `package`
# @example
# include promtail
#
Expand All @@ -75,7 +83,7 @@
# target_config_hash => $target_config_hash,
# bin_dir => $bin_dir,
# checksum => $checksum,
# version => $version,
# version => $binaryversion,
# }
#
# @example Settings in a Hiera file
Expand Down Expand Up @@ -123,19 +131,25 @@
# }
#
class promtail (
Boolean $service_enable,
Enum['running', 'stopped'] $service_ensure,
Hash $clients_config_hash,
Hash $positions_config_hash,
Hash $scrape_configs_hash,
Stdlib::Absolutepath $bin_dir,
String[1] $checksum,
String[1] $version,
Optional[Hash] $server_config_hash = undef,
Optional[Hash] $target_config_hash = undef,
Optional[Stdlib::Absolutepath] $password_file_path = undef,
Optional[Sensitive[String[1]]] $password_file_content = undef,
Stdlib::HTTPUrl $source_url = 'https://github.com/grafana/loki/releases/download',
Optional[Boolean] $service_enable = false,
Optional[Enum['running', 'stopped']] $service_ensure = 'stopped',
Optional[Hash] $clients_config_hash,
Optional[Hash] $positions_config_hash,
Optional[Hash] $scrape_configs_hash,
Optional[Stdlib::Absolutepath] $bin_dir = '/usr/bin',
Optional[String[1]] $binaryversion = "v1.0.0",
Optional[String[1]] $checksum = undef,
Optional[Hash] $server_config_hash = undef,
Optional[Hash] $target_config_hash = undef,
Optional[Stdlib::Absolutepath] $password_file_path = '/etc/promtail/.gc_pw',
Optional[Sensitive[String[1]]] $password_file_content = undef,
Optional[Stdlib::Absolutepath] $password_app_file_path = '/etc/promtail/.gc_pw_app',
Optional[String[1]] $password_app_file_content = undef,
Optional[Stdlib::HTTPUrl] $source_url = 'https://github.com/grafana/loki/releases/download',
Optional[Enum['package', 'archive']] $install_method = 'package',
Optional[Enum['installed', 'latest', 'absent']] $package_ensure = 'latest',
Optional[String[1]] $package_name = 'promtail',
Optional[String[1]] $package_rpm_version = $package_ensure
) {
Class['promtail::install']
-> Class['promtail::config']
Expand Down
103 changes: 55 additions & 48 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,69 @@
#
# @api private
class promtail::install {
include archive
if $promtail::install_method == 'archive' {
assert_type(String[1], $promtail::checksum)
include archive

case $facts['os']['architecture'] {
'x86_64', 'amd64': { $arch = 'amd64' }
'aarch64': { $arch = 'arm64' }
'armv7l': { $arch = 'arm' }
default: { fail("Unsupported kernel architecture: ${facts['os']['architecture']}") }
}
case $facts['os']['architecture'] {
'x86_64', 'amd64': { $arch = 'amd64' }
'aarch64': { $arch = 'arm64' }
'armv7l': { $arch = 'arm' }
default: { fail("Unsupported kernel architecture: ${facts['os']['architecture']}") }
}

case $facts['kernel'] {
'Linux': {
$data_dir = '/usr/local/promtail_data'
if versioncmp($promtail::version, 'v0.3.0') > 0 {
$release_file_name = "promtail-linux-${arch}"
} else {
$release_file_name = "promtail_linux_${arch}"
case $facts['kernel'] {
'Linux': {
$data_dir = '/usr/local/promtail_data'
if versioncmp($promtail::binaryversion, 'v0.3.0') > 0 {
$release_file_name = "promtail-linux-${arch}"
} else {
$release_file_name = "promtail_linux_${arch}"
}
}
default: { fail("${facts['kernel']} is not yet supported") }
}
default: { fail("${facts['kernel']} is not yet supported") }
}

if versioncmp($promtail::version, 'v1.0.0') > 0 {
$archive_type = 'zip'
} else {
$archive_type = 'gz'
}
if versioncmp($promtail::binaryversion, 'v1.0.0') > 0 {
$archive_type = 'zip'
} else {
$archive_type = 'gz'
}

$version_dir = "${data_dir}/promtail-${promtail::version}"
$binary_path = "${version_dir}/${release_file_name}"
$version_dir = "${data_dir}/promtail-${promtail::binaryversion}"
$binary_path = "${version_dir}/${release_file_name}"

file { [$data_dir, $version_dir]:
ensure => directory,
}
file { [$data_dir, $version_dir]:
ensure => directory,
}

archive { "${binary_path}.gz":
ensure => present,
source => "${promtail::source_url}/${promtail::version}/${release_file_name}.${archive_type}",
extract => true,
extract_path => $version_dir,
creates => $binary_path,
checksum => $promtail::checksum,
checksum_type => 'sha256',
cleanup => false,
}
archive { "${binary_path}.gz":
ensure => present,
source => "${promtail::source_url}/${promtail::binaryversion}/${release_file_name}.${archive_type}",
extract => true,
extract_path => $version_dir,
creates => $binary_path,
checksum => $promtail::checksum,
checksum_type => 'sha256',
cleanup => false,
}

file {
$binary_path:
ensure => file,
mode => '0755',
require => Archive["${binary_path}.gz"],
;
"${promtail::bin_dir}/promtail":
ensure => link,
target => $binary_path,
require => File[$binary_path],
notify => Service['promtail'],
;
file {
$binary_path:
ensure => file,
mode => '0755',
require => Archive["${binary_path}.gz"],
;
"${promtail::bin_dir}/promtail":
ensure => link,
target => $binary_path,
require => File[$binary_path],
notify => Service['promtail'],
;
}
} elsif $promtail::install_method == 'package' {
package { $promtail::package_name:
ensure => $promtail::package_rpm_version ,
}
}
}
7 changes: 3 additions & 4 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
source => 'puppet:///modules/promtail/promtail.service',
notify => Service['promtail'],
}

service { 'promtail':
ensure => $promtail::service_ensure,
enable => $promtail::service_enable,
require => Systemd::Unit_file['promtail.service'],
ensure => $promtail::service_ensure,
enable => $promtail::service_enable,
}
}
default: { fail("${facts['kernel']} is not supported") }
Expand Down
22 changes: 16 additions & 6 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grafana-promtail",
"version": "2.1.0",
"version": "2.2.0",
"author": "grafana",
"summary": "Deploy and configure Grafana's Promtail",
"license": "Apache-2.0",
Expand All @@ -22,15 +22,23 @@
},
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 6.0.0 < 8.0.0"
"version_requirement": ">= 6.0.0 < 9.0.0"
}
],
"operatingsystem_support": [
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"7",
"8"
"8",
"9"
]
},
{
"operatingsystem": "AlmaLinux",
"operatingsystemrelease": [
"8",
"9"
]
},
{
Expand All @@ -44,7 +52,8 @@
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"7",
"8"
"8",
"9"
]
},
{
Expand All @@ -64,14 +73,15 @@
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"18.04",
"20.04"
"20.04",
"22.04"
]
}
],
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 6.1.0 < 8.0.0"
"version_requirement": ">= 6.1.0 < 9.0.0"
}
],
"pdk-version": "2.2.0",
Expand Down
Loading