From 6fa35a923b2fcfafe8626c8dcff298af2db7a419 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sun, 13 Mar 2022 14:06:36 +0900 Subject: [PATCH] Retrieve IP address. --- cookbooks/vault/attributes.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cookbooks/vault/attributes.rb b/cookbooks/vault/attributes.rb index 4124518..eb30f07 100644 --- a/cookbooks/vault/attributes.rb +++ b/cookbooks/vault/attributes.rb @@ -1,8 +1,22 @@ # ------------------------------------------- # 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!({ 'vault' => { 'manager' => false, + 'ipaddr' => ipaddr, } })