Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support upgrades and consul service registration (bis) #24

Closed
wants to merge 4 commits into from
Closed
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
24 changes: 13 additions & 11 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@

if $vault::manage_config_file {
$_config_hash = delete_undef_values({
'listener' => $vault::listener,
'storage' => $vault::storage,
'ha_storage' => $vault::ha_storage,
'seal' => $vault::seal,
'telemetry' => $vault::telemetry,
'disable_cache' => $vault::disable_cache,
'default_lease_ttl' => $vault::default_lease_ttl,
'max_lease_ttl' => $vault::max_lease_ttl,
'disable_mlock' => $vault::disable_mlock,
'ui' => $vault::enable_ui,
'api_addr' => $vault::api_addr,
'listener' => $vault::listener,
'storage' => $vault::storage,
'ha_storage' => $vault::ha_storage,
'seal' => $vault::seal,
'telemetry' => $vault::telemetry,
'disable_cache' => $vault::disable_cache,
'default_lease_ttl' => $vault::default_lease_ttl,
'max_lease_ttl' => $vault::max_lease_ttl,
'disable_mlock' => $vault::disable_mlock,
'ui' => $vault::enable_ui,
'api_addr' => $vault::api_addr,
'service_registration' => $vault::service_registration,
})

$config_hash = merge($_config_hash, $vault::extra_config)
Expand All @@ -37,6 +38,7 @@
owner => $vault::user,
group => $vault::group,
mode => $vault::config_mode,
notify => Class['vault::service'],
}

# If manage_storage_dir is true and a file or raft storage backend is
Expand Down
22 changes: 15 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
#
# @param manage_repo Configure the upstream HashiCorp repository. Only relevant when $nomad::install_method = 'repo'.
#
# @param manage_service Instruct puppet to manage service or not
# * `service_registration`
# Extra configuration for service registration.
# `vault server --help`
#
# * `manage_service`
# Instruct puppet to manage service or not
#
# @param num_procs
# Sets the GOMAXPROCS environment variable, to determine how many CPUs Vault
Expand Down Expand Up @@ -62,6 +67,7 @@
# @param manage_file_capabilities
# @param disable_mlock
# @param max_lease_ttl
# @param service_registration
# @param default_lease_ttl
# @param telemetry
# @param disable_cache
Expand All @@ -70,18 +76,23 @@
# @param listener
# @param manage_storage_dir
# @param storage
# @param manage_service Instruct puppet to manage service or not
# @param manage_service_file
# @param service_ensure
# @param service_enable
# @param manage_config_file
# @param download_filename
# @param manage_config_dir enable/disable the directory management. not required for package based installations
class vault (
$arch = $vault::params::arch,
$bin_dir = $vault::params::bin_dir,
Boolean $manage_repo = $vault::params::manage_repo,
$manage_service_file = $vault::params::manage_service_file,
$install_method = $vault::params::install_method,
$user = 'vault',
$manage_user = true,
$group = 'vault',
$manage_group = true,
$bin_dir = $vault::params::bin_dir,
$manage_config_file = true,
$config_mode = '0750',
$purge_config_dir = true,
Expand All @@ -92,23 +103,21 @@
$service_enable = true,
$service_ensure = 'running',
$service_provider = $facts['service_provider'],
Boolean $manage_repo = $vault::params::manage_repo,
$manage_service = true,
Optional[Boolean] $manage_service_file = $vault::params::manage_service_file,
Hash $storage = { 'file' => { 'path' => '/var/lib/vault' } },
$manage_storage_dir = false,
Variant[Hash, Array[Hash]] $listener = { 'tcp' => { 'address' => '127.0.0.1:8200', 'tls_disable' => 1 }, },
Variant[Hash, Array[Hash]] $listener = { 'tcp' => { 'address' => '127.0.0.1:8200', 'tls_disable' => 1 } },
Optional[Hash] $ha_storage = undef,
Optional[Hash] $seal = undef,
Optional[Boolean] $disable_cache = undef,
Optional[Hash] $telemetry = undef,
Optional[String] $default_lease_ttl = undef,
Optional[String] $max_lease_ttl = undef,
Optional[Hash] $service_registration = undef,
$disable_mlock = undef,
$manage_file_capabilities = undef,
$service_options = '',
$num_procs = $facts['processors']['count'],
$install_method = $vault::params::install_method,
$config_dir = if $install_method == 'repo' and $manage_repo { '/etc/vault.d' } else { '/etc/vault' },
$package_name = 'vault',
$package_ensure = 'installed',
Expand All @@ -117,7 +126,6 @@
$download_filename = 'vault.zip',
$version = '1.12.0',
$os = downcase($facts['kernel']),
$arch = $vault::params::arch,
Optional[Boolean] $enable_ui = undef,
Optional[String] $api_addr = undef,
Hash $extra_config = {},
Expand Down
21 changes: 18 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,32 @@
}
}

$_manage_file_capabilities = true
$_vault_versioned_bin = "/opt/vault-${vault::version}/vault"

file { "/opt/vault-${vault::version}":
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}

archive { "${vault::download_dir}/${vault::download_filename}":
ensure => present,
extract => true,
extract_path => $vault::bin_dir,
extract_path => "/opt/vault-${vault::version}",
source => $vault::real_download_url,
cleanup => true,
creates => $vault_bin,
creates => $_vault_versioned_bin,
before => File['vault_binary'],
notify => Exec['install_versioned_vault'],
}

$_manage_file_capabilities = true
exec { 'install_versioned_vault':
command => "/bin/cp -f ${_vault_versioned_bin} ${vault_bin}",
refreshonly => true,
notify => Class['vault::service'],
}
}

'repo': {
Expand Down
40 changes: 30 additions & 10 deletions spec/classes/vault_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
max_lease_ttl: exist,
disable_mlock: exist,
ui: exist,
api_addr: exist
api_addr: exist,
service_registration: exist
)
end
end
Expand Down Expand Up @@ -131,31 +132,49 @@
}
end

context 'when service_registration is set' do
let(:params) do
{
service_registration: { 'consul' => { 'address' => '127.0.0.1:8500' } }
}
end

it {
expect(param_value(catalogue, 'File', '/etc/vault/config.json', 'content')).to include_json(
service_registration: { 'consul' => { 'address' => '127.0.0.1:8500' } }
)
}
end

context 'when installed from archive' do
let(:params) { { install_method: 'archive' } }

it {
is_expected.to contain_archive('/tmp/vault.zip').
that_comes_before('File[vault_binary]')
}

it {
is_expected.to contain_file('/etc/vault').
is_expected.to contain_file('/opt/vault-1.12.0').
with_ensure('directory').
with_purge('true').
with_recurse('true').
with_owner('vault').
with_group('vault')
with_owner('root').
with_group('root').
with_mode('0755')
}

context 'when installed with default download options' do
let(:params) do
super().merge(version: '0.7.0')
super().merge(
version: '0.7.0'
)
end

it {
is_expected.to contain_file('/opt/vault-0.7.0')
is_expected.to contain_archive('/tmp/vault.zip').
with_source('https://releases.hashicorp.com/vault/0.7.0/vault_0.7.0_linux_amd64.zip')
# A regex is used to validate the command because vault bin_dir is OS specific
is_expected.to contain_exec('install_versioned_vault').
with_command(%r{/bin/cp -f /opt/vault-0.7.0/vault /[\w/]+/vault}).
with_refreshonly(true).
that_notifies(['Class[vault::service]'])
}
end

Expand All @@ -170,6 +189,7 @@
end

it {
is_expected.to contain_file('/opt/vault-0.6.0')
is_expected.to contain_archive('/tmp/vault.zip').
with_source('http://my_site.example.com/vault/0.6.0/vaultbinary_0.6.0_linux_amd64.tar.gz')
}
Expand Down