From 9d1d6018bd54dc2a90ff67d09c626b632f145ebc Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 31 Oct 2020 16:51:38 +0900 Subject: [PATCH] Install `vector`. --- cookbooks/vector/attributes.rb | 23 ++++++++++++++++++++++ cookbooks/vector/default.rb | 6 ++++++ cookbooks/vector/install.rb | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 cookbooks/vector/attributes.rb create mode 100644 cookbooks/vector/default.rb create mode 100644 cookbooks/vector/install.rb diff --git a/cookbooks/vector/attributes.rb b/cookbooks/vector/attributes.rb new file mode 100644 index 0000000..0c0ffe4 --- /dev/null +++ b/cookbooks/vector/attributes.rb @@ -0,0 +1,23 @@ +# ------------------------------------------- +# Specifying the default settings: +# ------------------------------------------- +case run_command('grep VERSION_ID /etc/os-release | awk -F\" \'{print $2}\'').stdout.chomp +when "20.04" + cmd = 'LANG=C ip a | grep "inet " | grep -v -E "(127|172)" | cut -d" " -f6 | perl -pe "s/\/.+//g"' + +when "18.04" + cmd = 'LANG=C /sbin/ifconfig | grep "inet " | grep -v -E "(127|172)" | cut -d" " -f10' + +else + cmd = 'LANG=C /sbin/ifconfig | grep "inet addr" | grep -v -E "(127|172)" | awk "{print $2;}" | cut -d: -f2 | cut -f 1 -d " " | tail -1' +end + +ipaddr = run_command(cmd).stdout.chomp + +node.reverse_merge!({ + 'vector' => { + 'url' => 'https://github.com/timberio/vector/releases/download/', + 'ipaddr' => ipaddr, + 'deb' => 'vector-amd64.deb' + }, +}) diff --git a/cookbooks/vector/default.rb b/cookbooks/vector/default.rb new file mode 100644 index 0000000..b7d07c1 --- /dev/null +++ b/cookbooks/vector/default.rb @@ -0,0 +1,6 @@ +# Loading the attributes: +include_recipe './attributes.rb' + +# Install loki here: +include_recipe './install.rb' + diff --git a/cookbooks/vector/install.rb b/cookbooks/vector/install.rb new file mode 100644 index 0000000..8a77217 --- /dev/null +++ b/cookbooks/vector/install.rb @@ -0,0 +1,36 @@ +vector_url = '' +vector_deb = '' + +tag = '' +vtag = '' + +# Calculate the Download URL: +begin + require 'net/http' + + uri = URI.parse('https://github.com/timberio/vector/releases/latest') + + Timeout.timeout(3) do + response = Net::HTTP.get_response(uri) + + vtag = $1 if response.body =~ %r{tag\/(v\d+\.\d+\.\d+)} + tag = vtag.sub(/^v/, '') + + vector_deb = "#{node['vector']['deb']}" + vector_url = "#{node['vector']['url']}/#{vtag}/#{vector_deb}" + end +rescue + # Abort the chef client process: + raise 'Cannot connect to http://github.com.' +end + +# バージョン確認して、アップデート必要かどうか確認 +result = run_command("vector --version 2>&1 | grep #{tag}", error: false) +if result.exit_status != 0 + # Download: + TMP = "/tmp/#{vector_deb}" + + execute "wget #{vector_url} -O #{TMP}" + + execute "dpkg -i #{TMP}" +end