diff --git a/lib/facter/vault_version.rb b/lib/facter/vault_version.rb new file mode 100644 index 0000000..f65de5b --- /dev/null +++ b/lib/facter/vault_version.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Fact: vault_version +# +# Purpose: Retrieve vault version if installed +# +Facter.add(:vault_version) do + setcode do + if Facter::Util::Resolution.which('vault') + vault_server_version_output = Facter::Util::Resolution.exec('vault version') + match = vault_server_version_output.match(%r{Vault v(\d+\.\d+\.\d+)}) + match ? match.captures.first : nil + end + end + end + \ No newline at end of file diff --git a/manifests/install.pp b/manifests/install.pp index c1a99e1..1b76965 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -19,7 +19,13 @@ extract_path => $vault::bin_dir, source => $vault::real_download_url, cleanup => true, - creates => $vault_bin, + creates => $facts['vault_version'] ? { # lint:ignore:selector_inside_resource + undef => $vault_bin, + default => versioncmp($vault::version, $facts['vault_version']) > 0 ? { + true => undef, + default => $vault_bin + } + }, before => File['vault_binary'], }