Puppet Class: nomad

Defined in:
manifests/init.pp

Overview

Installs, configures, and manages nomad

Examples:

To set up a single nomad server, with several agents attached, on the server.

class { 'nomad':
  config_hash => {
    'region'     => 'us-west',
    'datacenter' => 'ptk',
    'log_level'  => 'INFO',
    'bind_addr'  => '0.0.0.0',
    'data_dir'   => '/opt/nomad',
    'server'     => {
      'enabled'          => true,
      'bootstrap_expect' => 3,
    }
  }
}

On the agent(s)

class { 'nomad':
  config_hash => {
    'region'     => 'us-west',
    'datacenter' => 'ptk',
    'log_level'  => 'INFO',
    'bind_addr'  => '0.0.0.0',
    'data_dir'   => '/opt/nomad',
    'client'     => {
      'enabled' => true,
      'servers' => [
        "nomad01.your-org.pvt:4647",
        "nomad02.your-org.pvt:4647",
        "nomad03.your-org.pvt:4647"
      ]
    }
  },
}

Install from zip file for a CPU architecture HashiCorp does not provide native packages for.

class { 'nomad':
  arch                => 'armv7l',
  install_method      => 'url',
  manage_service_file => true,
  version             => '1.0.3', # check latest version at https://github.com/hashicorp/nomad/blob/master/CHANGELOG.md
  config_hash         => {
    'region'     => 'us-west',
    'datacenter' => 'ptk',
    'log_level'  => 'INFO',
    'bind_addr'  => '0.0.0.0',
    'data_dir'   => '/opt/nomad',
    'client'     => {
      'enabled' => true,
      'servers' => [
        "nomad01.your-org.pvt:4647",
        "nomad02.your-org.pvt:4647",
        "nomad03.your-org.pvt:4647"
      ]
    }
  },
}

Disable install and service components

class { 'nomad':
  install_method => 'none',
  manage_service => false,
  config_hash    => {
    region     => 'us-west',
    datacenter => 'ptk',
    log_level  => 'INFO',
    bind_addr  => '0.0.0.0',
    data_dir   => '/opt/nomad',
    'client'     => {
      'enabled' => true,
      'servers' => [
        "nomad01.your-org.pvt:4647",
        "nomad02.your-org.pvt:4647",
        "nomad03.your-org.pvt:4647"
      ]
    }
  },
}

Parameters:

  • arch (String[1])

    cpu architecture

  • purge_config_dir (Boolean) (defaults to: true)

    Purge config files no longer generated by Puppet

  • data_dir_mode (Stdlib::Filemode) (defaults to: '0755')

    Specify unix permissions for data dir directory managed by this module

  • join_wan (Optional[String[1]]) (defaults to: undef)

    join nomad cluster over the WAN

  • bin_dir (Stdlib::Absolutepath) (defaults to: '/usr/bin')

    location of the nomad binary

  • version (String[1]) (defaults to: 'installed')

    Specify version of nomad binary to download.

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

    install via system package, download and extract from a url.

  • os (String[1]) (defaults to: downcase($facts['kernel']))

    operation system to install for

  • download_url (Optional[String[1]]) (defaults to: undef)

    download url to download from

  • download_url_base (String[1]) (defaults to: 'https://releases.hashicorp.com/nomad/')

    download hostname to down from

  • download_extension (String[1]) (defaults to: 'zip')

    archive type to download

  • package_name (String[1]) (defaults to: 'nomad')

    Only valid when the install_method == package.

  • config_dir (Stdlib::Absolutepath) (defaults to: '/etc/nomad.d')

    location of the nomad configuration

  • extra_options (Optional[String[1]]) (defaults to: undef)

    Extra arguments to be passed to the nomad agent

  • config_hash (Hash) (defaults to: {})

    Use this to populate the JSON config file for nomad.

  • config_defaults (Hash) (defaults to: {})

    default set of config settings

  • config_mode (Stdlib::Filemode) (defaults to: '0660')

    Use this to set the JSON config file mode for nomad.

  • manage_repo (Boolean) (defaults to: true)

    Configure the upstream HashiCorp repository. Only relevant when $nomad::install_method = ‘package’.

  • manage_service (Boolean) (defaults to: true)

    manage the nomad service

  • manage_service_file (Boolean) (defaults to: false)

    create and manage the systemd service file

  • pretty_config (Boolean) (defaults to: false)

    Generates a human readable JSON config file.

  • service_enable (Boolean) (defaults to: true)

    enable the nomad service

  • service_ensure (Stdlib::Ensure::Service) (defaults to: 'running')

    ensure the state of the nomad service

  • restart_on_change (Boolean) (defaults to: true)

    Determines whether to restart nomad agent on $config_hash changes. This will not affect reloads when service, check or watch configs change.

  • env_vars (Hash[String[1], String]) (defaults to: {})

    Hash of optional environment variables that should be passed to nomad

  • user (String[1]) (defaults to: 'root')

    User to run the Nomad binary as. Also used as owner of directories and config files managed by this module.

  • group (String[1]) (defaults to: 'root')

    Group to run the Nomad binary as. Also used as group of directories and config files managed by this module.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'manifests/init.pp', line 135

class nomad (
  String[1] $arch,
  Boolean $purge_config_dir                      = true,
  Stdlib::Filemode $data_dir_mode                = '0755',
  Optional[String[1]] $join_wan                  = undef,
  Stdlib::Absolutepath $bin_dir                  = '/usr/bin',
  String[1] $version                             = 'installed',
  Enum['none', 'package', 'url'] $install_method = 'package',
  String[1] $os                                  = downcase($facts['kernel']),
  Optional[String[1]] $download_url              = undef,
  String[1] $download_url_base                   = 'https://releases.hashicorp.com/nomad/',
  String[1] $download_extension                  = 'zip',
  String[1] $package_name                        = 'nomad',
  Stdlib::Absolutepath $config_dir               = '/etc/nomad.d',
  Optional[String[1]] $extra_options             = undef,
  Hash $config_hash                              = {},
  Hash $config_defaults                          = {},
  Stdlib::Filemode $config_mode                  = '0660',
  Boolean $pretty_config                         = false,
  Boolean $service_enable                        = true,
  Stdlib::Ensure::Service $service_ensure        = 'running',
  Boolean $manage_repo                           = true,
  Boolean $manage_service                        = true,
  Boolean $manage_service_file                   = false,
  Boolean $restart_on_change                     = true,
  Hash[String[1], String] $env_vars              = {},
  String[1] $user                                = 'root',
  String[1] $group                               = 'root',
) {
  $real_download_url = pick($download_url, "${download_url_base}${version}/${package_name}_${version}_${os}_${arch}.${download_extension}")
  $config_hash_real = deep_merge($config_defaults, $config_hash)

  if $config_hash_real['data_dir'] {
    $data_dir = $config_hash_real['data_dir']
  } else {
    $data_dir = undef
  }

  if ($config_hash_real['ports'] and $config_hash_real['ports']['rpc']) {
    $rpc_port = $config_hash_real['ports']['rpc']
  } else {
    $rpc_port = 8400
  }

  if ($config_hash_real['addresses'] and $config_hash_real['addresses']['rpc']) {
    $rpc_addr = $config_hash_real['addresses']['rpc']
  } elsif ($config_hash_real['client_addr']) {
    $rpc_addr = $config_hash_real['client_addr']
  } else {
    $rpc_addr = $facts['networking']['interfaces']['lo']['ip']
  }

  $notify_service = $restart_on_change ? {
    true    => Class['nomad::run_service'],
    default => undef,
  }

  class { 'nomad::install': }
  -> class { 'nomad::config':
    notify => $notify_service,
  }
  -> class { 'nomad::run_service': }
  -> class { 'nomad::reload_service': }

  contain nomad::install
  contain nomad::config
  contain nomad::run_service
  contain nomad::reload_service
}