kswem
October 18, 2016, 6:45pm
1
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}’ ?
kswem
October 18, 2016, 7:42pm
3
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: ")}
kswem
October 18, 2016, 7:56pm
4
Was actually hoping I could do something like:
(knife node show server1 -a ipaddress).value
But oh well!
Aia
March 13, 2017, 2:47am
5
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
Aia
March 13, 2017, 3:07am
7
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?
Aia
March 13, 2017, 3:24am
8
I think I get it.
knife exec -E ‘puts nodes.methods’ does give me a lot of things I can do.