From d0dacca340b18ba73187e53aeba8ff0847091715 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 26 Oct 2019 23:07:11 +0800 Subject: [PATCH 2/2] Exclude "127" and "172" (= Docker) IP addresses. --- cookbooks/consul/attributes.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cookbooks/consul/attributes.rb b/cookbooks/consul/attributes.rb index dd163ed..a2627d1 100644 --- a/cookbooks/consul/attributes.rb +++ b/cookbooks/consul/attributes.rb @@ -3,9 +3,9 @@ # ------------------------------------------- case run_command('grep VERSION_ID /etc/os-release | awk -F\" \'{print $2}\'').stdout.chomp when "18.04" - cmd = 'LANG=C /sbin/ifconfig | grep "inet " | grep 192.168 | cut -d" " -f10' + 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 192.168 | awk "{print $2;}" | cut -d: -f2 | cut -f 1 -d " " | tail -1' + 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