Install `vector`.

This commit is contained in:
Kazuhiro MUSASHI 2020-10-31 16:51:38 +09:00
parent c26045a1ab
commit 9d1d6018bd
3 changed files with 65 additions and 0 deletions

View File

@ -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'
},
})

View File

@ -0,0 +1,6 @@
# Loading the attributes:
include_recipe './attributes.rb'
# Install loki here:
include_recipe './install.rb'

View File

@ -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