Skip to content

Commit e38cf0d

Browse files
committed
Support upgrades and trigger restart of vault
Closes /pull/154 Closes jsok/puppet-vault/issues/63
1 parent 6889893 commit e38cf0d

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

manifests/config.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
owner => $::vault::user,
3636
group => $::vault::group,
3737
mode => $::vault::config_mode,
38+
notify => Class['vault::service'],
3839
}
3940

4041
# If using the file storage then the path must exist and be readable

manifests/install.pp

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
11
# == Class vault::install
22
#
33
class vault::install {
4+
45
$vault_bin = "${::vault::bin_dir}/vault"
56

67
case $::vault::install_method {
7-
'archive': {
8-
if $::vault::manage_download_dir {
9-
file { $::vault::download_dir:
10-
ensure => directory,
11-
}
8+
'archive': {
9+
if $::vault::manage_download_dir {
10+
file { $::vault::download_dir:
11+
ensure => directory,
1212
}
13+
}
1314

14-
archive { "${::vault::download_dir}/${::vault::download_filename}":
15-
ensure => present,
16-
extract => true,
17-
extract_path => $::vault::bin_dir,
18-
source => $::vault::real_download_url,
19-
cleanup => true,
20-
creates => $vault_bin,
21-
before => File['vault_binary'],
22-
}
15+
$_manage_file_capabilities = true
16+
$_vault_versioned_bin = "/opt/vault-${::vault::version}/vault"
17+
18+
file { "/opt/vault-${::vault::version}":
19+
ensure => directory,
20+
owner => 'root',
21+
group => 'root',
22+
mode => '0755',
23+
}
2324

24-
$_manage_file_capabilities = true
25+
archive { "${::vault::download_dir}/${::vault::download_filename}":
26+
ensure => present,
27+
extract => true,
28+
extract_path => "/opt/vault-${::vault::version}",
29+
source => $::vault::real_download_url,
30+
cleanup => true,
31+
creates => $_vault_versioned_bin,
32+
before => File['vault_binary'],
33+
notify => Exec['install_versioned_vault'],
2534
}
2635

36+
exec { 'install_versioned_vault':
37+
command => "/bin/cp -f ${_vault_versioned_bin} ${vault_bin}",
38+
refreshonly => true,
39+
notify => Class['vault::service'],
40+
}
41+
42+
}
43+
2744
'repo': {
2845
package { $::vault::package_name:
2946
ensure => $::vault::package_ensure,
@@ -37,7 +54,7 @@
3754
}
3855

3956
file { 'vault_binary':
40-
path => $vault_bin,
57+
path => $vault_bin,
4158
owner => 'root',
4259
group => 'root',
4360
mode => '0755',

spec/classes/vault_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,29 @@
147147
it {
148148
is_expected.to contain_archive('/tmp/vault.zip').
149149
that_comes_before('File[vault_binary]')
150+
is_expected.to contain_file('/opt/vault-1.4.2').
151+
with_ensure('directory').
152+
with_owner('root').
153+
with_group('root').
154+
with_mode('0755')
150155
}
151156

152157
context 'when installed with default download options' do
153158
let(:params) do
154-
super().merge(version: '0.7.0')
159+
super().merge(
160+
version: '0.7.0',
161+
)
155162
end
156163

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

@@ -171,6 +184,7 @@
171184
end
172185

173186
it {
187+
is_expected.to contain_file('/opt/vault-0.6.0')
174188
is_expected.to contain_archive('/tmp/vault.zip').
175189
with_source('http://my_site.example.com/vault/0.6.0/vaultbinary_0.6.0_linux_amd64.tar.gz')
176190
}

0 commit comments

Comments
 (0)