How can I get IP address returned by node search in chef recipe (ruby).
dbnodes = search(:node, "role:Db")
Chef::Log.info(dbnodes.first["ipaddress"]) # nil
Few weeks ago this code returned IP of first instance from search API.
version: Chef: 10.14.2
I'm guessing that you're new to Ruby. If so, welcome!
The Chef search()
function returns an array of Chef nodes and you are taking the head of this array using the first
method. To access the IP address of the other nodes use the regular array operator:
dbnodes = search(:node, "role:Db")
dbnodes.each do |node|
Chef::Log.info("#{node["name"]} has IP address #{node["ipaddress"]}")
end
This should give you the information you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With