サーバBのeth2のアドレスを取ってきて、テストに使いたい。
って時に、特定NICのアドレスが欲しくなる。
OhaiのJSONがこんな感じで返ってくるので、Rubyを知らないとどうやって取るのか悩んでしまったのでメモ。
"eth0": { "flags": [ "BROADCAST", "MULTICAST", "UP", "LOWER_UP" ], "addresses": { "192.168.1.98": { "broadcast": "192.168.1.255", "netmask": "255.255.255.0", "prefixlen": "24", "scope": "Global", "family": "inet" }, "52:54:00:5A:2C:F6": { "family": "lladdr" }, "fe80::5054:ff:fe5a:2cf6": { "prefixlen": "64", "family": "inet6", "scope": "Link" }, "2001:c90:8000:c0e:5054:ff:fe5a:2cf6": { "prefixlen": "64", "family": "inet6", "scope": "Global" } },
■chef
node["network"]["interfaces"]["eth1"]["addresses"].select { |address, data| data["family"] == "inet" }[0][0]
■ohai
require 'rubygems' require 'ohai' oh = Ohai::System.new oh.all_plugins p oh["network"]["interfaces"]["eth2"]["addresses"].select { |address, data| data["family"] == "inet" }[0][0]
0 件のコメント:
コメントを投稿