Skip to content

Commit 1b2b9e7

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

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

manifests/config.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
owner => $vault::user,
3838
group => $vault::group,
3939
mode => $vault::config_mode,
40+
owner => $::vault::user,
41+
group => $::vault::group,
42+
mode => $::vault::config_mode,
43+
notify => Class['vault::service'],
4044
}
4145

4246
# If manage_storage_dir is true and a file or raft storage backend is

manifests/install.pp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,43 @@
33
#
44
class vault::install {
55
assert_private()
6-
$vault_bin = "${vault::bin_dir}/vault"
6+
$vault_bin = "${::vault::bin_dir}/vault"
77

8-
case $vault::install_method {
8+
case $::vault::install_method {
99
'archive': {
10-
if $vault::manage_download_dir {
11-
file { $vault::download_dir:
10+
if $::vault::manage_download_dir {
11+
file { $::vault::download_dir:
1212
ensure => directory,
1313
}
1414
}
1515

16-
archive { "${vault::download_dir}/${vault::download_filename}":
16+
$_manage_file_capabilities = true
17+
$_vault_versioned_bin = "/opt/vault-${::vault::version}/vault"
18+
19+
file { "/opt/vault-${::vault::version}":
20+
ensure => directory,
21+
owner => 'root',
22+
group => 'root',
23+
mode => '0755',
24+
}
25+
26+
archive { "${::vault::download_dir}/${::vault::download_filename}":
1727
ensure => present,
1828
extract => true,
19-
extract_path => $vault::bin_dir,
20-
source => $vault::real_download_url,
29+
extract_path => "/opt/vault-${::vault::version}",
30+
source => $::vault::real_download_url,
2131
cleanup => true,
22-
creates => $vault_bin,
32+
creates => $_vault_versioned_bin,
2333
before => File['vault_binary'],
34+
notify => Exec['install_versioned_vault'],
35+
}
36+
37+
exec { 'install_versioned_vault':
38+
command => "/bin/cp -f ${_vault_versioned_bin} ${vault_bin}",
39+
refreshonly => true,
40+
notify => Class['vault::service'],
2441
}
2542

26-
$_manage_file_capabilities = true
2743
}
2844

2945
'repo': {

spec/classes/vault_spec.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,29 @@
137137
it {
138138
is_expected.to contain_archive('/tmp/vault.zip').
139139
that_comes_before('File[vault_binary]')
140-
}
141-
142-
it {
143-
is_expected.to contain_file('/etc/vault').
140+
is_expected.to contain_file('/opt/vault-1.4.2').
144141
with_ensure('directory').
145-
with_purge('true').
146-
with_recurse('true').
147-
with_owner('vault').
148-
with_group('vault')
142+
with_owner('root').
143+
with_group('root').
144+
with_mode('0755')
149145
}
150146

151147
context 'when installed with default download options' do
152148
let(:params) do
153-
super().merge(version: '0.7.0')
149+
super().merge(
150+
version: '0.7.0',
151+
)
154152
end
155153

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

@@ -170,6 +174,7 @@
170174
end
171175

172176
it {
177+
is_expected.to contain_file('/opt/vault-0.6.0')
173178
is_expected.to contain_archive('/tmp/vault.zip').
174179
with_source('http://my_site.example.com/vault/0.6.0/vaultbinary_0.6.0_linux_amd64.tar.gz')
175180
}

0 commit comments

Comments
 (0)