Retrieve IP address.

This commit is contained in:
Kazuhiro MUSASHI 2022-03-13 14:06:36 +09:00
parent a917563b06
commit 6fa35a923b
1 changed files with 14 additions and 0 deletions

View File

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