How to get 'value only' for node IP address or FQDN?

If I enter the following I can get the node’s IP address or FQDN:

knife node show server1 -a fqdn

Which returns:

server1:
fqdn: SERVER1.domain.com

OR, for IP Address:

knife node show server1 -a ipaddress

Which returns:

server1: ipaddress: 10.224.01.02

What I want to do is just return the value only:

SERVER1.domain.com
OR
10.224.01.02

…so I can store in a variable and pass in later.

How can I return just the value of the fqdn or ipaddress?

BTW: I need to do this outside of Chef, like in a PowerShell script, if possible.

Thanks,
Keith

knife node show server1 -a ipaddress | grep ipaddress | awk -F: ‘{print $2}’ ? :slight_smile:

Hehe…was on the same wavelength. Did something similar in PowerShell but not quite as elegant:

[string](knife node show server1 -a ipaddress | Select-String 'ipaddress:' -simplematch) | % {$_.Trim(" ipaddress: ")}

Was actually hoping I could do something like:

(knife node show server1 -a ipaddress).value

But oh well! :slight_smile:

May I suggest to remove grep since AWK doesn’t need it?
knife node show server1 -a ipaddress | awk '$1=="ipaddress:" {print $2}'

Or you can skip all of that:

knife exec -E 'puts nodes.load("server1")["ipaddress"]'

Scripting is your friend.

1 Like

Many thanks, coderanger!
Where can I find out what sort of things I could script. For example, how can I know that there is such a thing like nodes.load?

I think I get it.
knife exec -E ‘puts nodes.methods’ does give me a lot of things I can do.