diff --git a/REFERENCE.md b/REFERENCE.md
index dddd4d2..b34de69 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -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)
##### `service_enable`
@@ -228,6 +231,30 @@ The URL from which promtail packages can be downloaded
Default value: `'https://github.com/grafana/loki/releases/download'`
+##### `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'`
+
+##### `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'`
+
+##### `package_name`
+
+Data type: `String[1]`
+
+The name of the package. Only used if `$install_method` is set to `package`
+
+Default value: `'promtail'`
+
## Functions
### `promtail::strip_yaml_header`
diff --git a/files/promtail.service b/files/promtail.service
index bce07c2..a44e69b 100644
--- a/files/promtail.service
+++ b/files/promtail.service
@@ -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
diff --git a/manifests/config.pp b/manifests/config.pp
index 695c6bf..bb399f7 100644
--- a/manifests/config.pp
+++ b/manifests/config.pp
@@ -15,7 +15,7 @@
ensure => directory,
}
- $config_file = "${config_dir}/config.yaml"
+ $config_file = "${config_dir}/config.yml"
concat { $config_file:
ensure => present,
@@ -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,
+ }
+ }
}
diff --git a/manifests/init.pp b/manifests/init.pp
index 6e89ff2..8515d70 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -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
#
@@ -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
#
@@ -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
@@ -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']
diff --git a/manifests/install.pp b/manifests/install.pp
index 3f415c5..14333ff 100644
--- a/manifests/install.pp
+++ b/manifests/install.pp
@@ -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 ,
+ }
}
}
diff --git a/manifests/service.pp b/manifests/service.pp
index e974a04..3b1f468 100644
--- a/manifests/service.pp
+++ b/manifests/service.pp
@@ -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") }
diff --git a/metadata.json b/metadata.json
index b8ba128..08d52de 100644
--- a/metadata.json
+++ b/metadata.json
@@ -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",
@@ -22,7 +22,7 @@
},
{
"name": "puppetlabs/stdlib",
- "version_requirement": ">= 6.0.0 < 8.0.0"
+ "version_requirement": ">= 6.0.0 < 9.0.0"
}
],
"operatingsystem_support": [
@@ -30,7 +30,15 @@
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"7",
- "8"
+ "8",
+ "9"
+ ]
+ },
+ {
+ "operatingsystem": "AlmaLinux",
+ "operatingsystemrelease": [
+ "8",
+ "9"
]
},
{
@@ -44,7 +52,8 @@
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"7",
- "8"
+ "8",
+ "9"
]
},
{
@@ -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",
diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb
index 0eb5908..fda7795 100644
--- a/spec/classes/install_spec.rb
+++ b/spec/classes/install_spec.rb
@@ -3,8 +3,9 @@
describe 'promtail::install' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
+ let(:facts) { os_facts }
+
context 'with valid params' do
- let(:facts) { os_facts }
let(:pre_condition) do
"class { 'promtail':
password_file_path => '/etc/promtail/.gc_pw',
@@ -45,9 +46,30 @@
}"
end
- it { is_expected.to compile }
+ it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file('/usr/local/bin/promtail').with_ensure('link') }
it { is_expected.to contain_file('/usr/local/promtail_data').with_ensure('directory') }
+ it { is_expected.to contain_file('/usr/local/promtail_data/promtail-v2.0.0/promtail-linux-amd64').with_ensure('file') }
+ it { is_expected.to contain_file('/usr/local/promtail_data/promtail-v2.0.0').with_ensure('directory') }
+ it { is_expected.to contain_archive('/usr/local/promtail_data/promtail-v2.0.0/promtail-linux-amd64.gz') }
+ it { is_expected.not_to contain_package('promtail') }
+ end
+
+ context 'with package based installation' do
+ let(:pre_condition) do
+ "class { 'promtail':
+ server_config_hash => {},
+ clients_config_hash => {},
+ positions_config_hash => {},
+ scrape_configs_hash => {},
+ install_method => 'package',
+ }"
+ end
+
+ it { is_expected.to compile.with_all_deps }
+ it { is_expected.not_to contain_file('/usr/local/bin/promtail') }
+ it { is_expected.not_to contain_file('/usr/local/promtail_data') }
+ it { is_expected.to contain_package('promtail') }
end
end
end