Puppet Class: thanos::install

Defined in:
manifests/install.pp

Summary

This class install Thanos requirements and binaries.

Overview

Examples:

include thanos::install

Parameters:

  • version (Pattern[/\d+\.\d+\.\d+/]) (defaults to: $thanos::version)
  • package_name (String) (defaults to: $thanos::package_name)

    Thanos package name - not available yet.

  • os (String) (defaults to: $thanos::os)

    Operating system.

  • real_arch (String) (defaults to: $thanos::real_arch)

    Architecture (amd64 or arm64).

  • package_ensure (Enum['present', 'absent', 'latest']) (defaults to: $thanos::package_ensure)

    If package, then use this for package ensurel default ‘latest’.

  • install_method (Enum['url', 'package', 'none']) (defaults to: $thanos::install_method)

    Installation method: url or package (only url is supported currently).

  • download_extension (String) (defaults to: $thanos::download_extension)

    Extension of Thanos binaries archive.

  • download_url (Stdlib::HTTPUrl) (defaults to: $thanos::real_download_url)

    Complete URL corresponding to the Prometheus release, default to undef.

  • extract_command (Optional[String]) (defaults to: $thanos::extract_command)

    Custom command passed to the archive resource to extract the downloaded archive.

  • base_dir (Stdlib::Absolutepath) (defaults to: $thanos::base_dir)

    Base directory where Thanos is extracted.

  • bin_dir (Stdlib::Absolutepath) (defaults to: $thanos::bin_dir)

    Directory where binaries are located.

  • config_dir (Stdlib::Absolutepath) (defaults to: $thanos::config_dir)

    Directory where configuration are located.

  • purge_config_dir (Boolean) (defaults to: $thanos::purge_config_dir)

    Purge configuration directory.

  • notify_services (Array[Type[Resource]]) (defaults to: $thanos::notify_services)

    Services to notify when binaries changed.

  • manage_user (Boolean) (defaults to: $thanos::manage_user)

    Whether to create user for thanos or rely on external code for that.

  • manage_group (Boolean) (defaults to: $thanos::manage_group)

    Whether to create user for thanos or rely on external code for that.

  • user (String) (defaults to: $thanos::user)

    User running thanos.

  • group (String) (defaults to: $thanos::group)

    Group under which thanos is running.

  • usershell (Stdlib::Absolutepath) (defaults to: $thanos::usershell)

    if requested, we create a user for thanos. The default shell is false. It can be overwritten to any valid path.

  • extra_groups (Array[String]) (defaults to: $thanos::extra_groups)

    Add other groups to the managed user.



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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'manifests/install.pp', line 45

class thanos::install (
  Pattern[/\d+\.\d+\.\d+/]            $version            = $thanos::version,
  String                              $package_name       = $thanos::package_name,
  String                              $os                 = $thanos::os,
  String                              $real_arch          = $thanos::real_arch,

  # Installation
  Enum['present', 'absent', 'latest'] $package_ensure     = $thanos::package_ensure,
  Enum['url', 'package', 'none']      $install_method     = $thanos::install_method,
  String                              $download_extension = $thanos::download_extension,
  Stdlib::HTTPUrl                     $download_url       = $thanos::real_download_url,
  Optional[String]                    $extract_command    = $thanos::extract_command,
  Stdlib::Absolutepath                $base_dir           = $thanos::base_dir,
  Stdlib::Absolutepath                $bin_dir            = $thanos::bin_dir,
  Stdlib::Absolutepath                $config_dir         = $thanos::config_dir,
  Boolean                             $purge_config_dir   = $thanos::purge_config_dir,
  Array[Type[Resource]]               $notify_services    = $thanos::notify_services,

  # User Management
  Boolean                             $manage_user        = $thanos::manage_user,
  Boolean                             $manage_group       = $thanos::manage_group,
  String                              $user               = $thanos::user,
  String                              $group              = $thanos::group,
  Stdlib::Absolutepath                $usershell          = $thanos::usershell,
  Array[String]                       $extra_groups       = $thanos::extra_groups,
) {
  assert_private()

  case $install_method {
    'url': {
      archive { "/tmp/thanos-${version}.${download_extension}":
        ensure          => present,
        extract         => true,
        extract_path    => $base_dir,
        source          => $download_url,
        checksum_verify => false,
        creates         => "${base_dir}/thanos-${version}.${os}-${real_arch}/thanos",
        cleanup         => true,
        extract_command => $extract_command,
      }
      -> file {
        "${base_dir}/thanos-${version}.${os}-${real_arch}/thanos":
          owner => 'root',
          group => 0, # 0 instead of root because OS X uses "wheel".
          mode  => '0555';
        "${bin_dir}/thanos":
          ensure => link,
          notify => $notify_services,
          target => "${base_dir}/thanos-${version}.${os}-${real_arch}/thanos";
      }
    }
    'package': {
      package { $package_name:
        ensure => $package_ensure,
        notify => $notify_services,
      }
      if $manage_user {
        User[$user] -> Package[$package_name]
      }
    }
    'none': {}
    default: {
      fail("The provided install method ${install_method} is invalid")
    }
  }

  if $manage_user {
    ensure_resource('user', [$user], {
        ensure => 'present',
        system => true,
        groups => concat([$group], $extra_groups),
        shell  => $usershell,
    })

    if $manage_group {
      Group[$group] -> User[$user]
    }
  }
  if $manage_group {
    ensure_resource('group', [$group], {
        ensure => 'present',
        system => true,
    })
  }

  file { $config_dir:
    ensure  => 'directory',
    owner   => 'root',
    group   => $group,
    purge   => $purge_config_dir,
    recurse => $purge_config_dir,
  }
}