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/manifests/init.pp b/manifests/init.pp
index 6e89ff2..608f21f 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -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
#
@@ -129,13 +137,16 @@
Hash $positions_config_hash,
Hash $scrape_configs_hash,
Stdlib::Absolutepath $bin_dir,
- String[1] $checksum,
String[1] $version,
+ Optional[String[1]] $checksum = undef,
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',
+ Enum['package', 'archive'] $install_method = 'archive',
+ Enum['installed', 'absent'] $package_ensure = 'installed',
+ String[1] $package_name = 'promtail',
) {
Class['promtail::install']
-> Class['promtail::config']
diff --git a/manifests/install.pp b/manifests/install.pp
index 3f415c5..79ce527 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::version, '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::version, '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::version}"
+ $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::version}/${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_ensure,
+ }
}
}
diff --git a/manifests/service.pp b/manifests/service.pp
index e974a04..72cbabd 100644
--- a/manifests/service.pp
+++ b/manifests/service.pp
@@ -6,15 +6,16 @@
class promtail::service {
case $facts['kernel'] {
'Linux': {
- systemd::unit_file { 'promtail.service':
- source => 'puppet:///modules/promtail/promtail.service',
- notify => Service['promtail'],
+ if $promtail::install_method == 'archive' {
+ systemd::unit_file { 'promtail.service':
+ 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/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