From e0820892d4dffad495747a0c1151ce5a87b1ad13 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Tue, 5 Nov 2019 23:37:15 +0800 Subject: [PATCH] Install `consul`, when finding a newer version. --- cookbooks/consul/install.rb | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/cookbooks/consul/install.rb b/cookbooks/consul/install.rb index 5fe4fb2..db1fffa 100644 --- a/cookbooks/consul/install.rb +++ b/cookbooks/consul/install.rb @@ -2,6 +2,7 @@ # Calculating the latest `consul` version: # ------------------------------------------- download_url = '' +tag_version = '' begin require 'net/http' @@ -26,22 +27,27 @@ end # Main Part # ------------------------------------------- -# Download: -execute "wget #{download_url} -O #{node['consul']['tmp_path']}" +# バージョン確認して、アップデート必要かどうか確認 +result = run_command("consul version | grep #{tag_version}", error: false) +if result.exit_status != 0 + # Download: + execute "wget #{download_url} -O #{node['consul']['tmp_path']}" -# Unzip: -execute "unzip -qo #{node['consul']['tmp_path']}" do - cwd '/opt/consul/bin/' + # Unzip: + execute "unzip -qo #{node['consul']['tmp_path']}" do + cwd '/opt/consul/bin/' + end + + file '/opt/consul/bin/consul' do + owner 'root' + group 'root' + mode '755' + end + + # Create link: + link '/usr/local/bin/consul' do + user 'root' + to '/opt/consul/bin/consul' + end end -file '/opt/consul/bin/consul' do - owner 'root' - group 'root' - mode '755' -end - -# Create link: -link '/usr/local/bin/consul' do - user 'root' - to '/opt/consul/bin/consul' -end