How do you query a VM for its private ip address?
I have tried a dozen different combinations of queries to try to get this but nothing seems to work.
Overall, is there a way to get a schema for a resource so I can use that to build these queries? I am trying to use 'show' to get details on a resource and construct the query from that but it's not helping.
thnaks.
az vm show -g {rg} -n {name} -d
sorry I should have been more specific. I just want to return the ipAddress itself as a string as I'm passing that to the --servers parameter to create an Application Gateway.
I've tried various combinations of...
az vm show -g $RgName -n Vm1 --query "{privateIps}" --out tsv
az vm show -g $RgName -n Vm1 --query "{ipConfigurations:privateIpAddress}" --out tsv
etc.
You need to use -d to get the additional VM details, because private IP address is not part of the schema for a VM.
Once you do, it will appear in the JSON output and you should be able to retrieve it the way you are trying to, If that doesn't work, there's a bug.
In general, the output you see with the show command is the schema you need to use for querying or generic update. This is precisely why we resist calls to manufacture special case outputs that arise from time to time.
Manufacturer?
typo: manufacture
In this case, I have verified this:
az vm show -g {rg} -n {name} -d --query privateIps -otsv
That syntax is confusing to me. I tried it like this. Is this what you mean?
az vm show -g {MyRG{ -n {MyVM} -d --query privateIps -otsv
Yes. Literally you just need to add -d to your original command you tried.
I get nothing back from that. Not even a "None".
ok, now it works. I was confused by all the braces you posted.
Thanks for clearing that up for me. Appreciate it. So this is what I used.
az vm show -g MyRG -n MyVM --query privateIps -d --out tsv
Yes, I think @derekbekoe provided you a way of getting the address through list-ip-addresses as well. Feel free to give feedback to the Compute team that this information should be available directly as read-only properties on the VM. :grin:
from a linux VM where AzureCLI 2.0 is installed :
-get the Public IP:
-get the Private IP:
same command replace the string "public" by "private"
That's kind of unnecessary. You can just do a JMESPath query to pull out the information you want based on the keys of the json that gets returned by az cli command. I've used something like this:
az vm list-ip-addresses -g {resource group name} -n {vm name} --query "[].virtualMachine.{network.privateIpAddresses[0]}" -o tsv
Which takes the json from 'az vm list-ip-addresses' and pulls out the value associated with the part that specifies the private ip address and then outputs it as a tab-separated value
How can i retrieve _primary private ip_?
Two methods:
e.g.
$ az vm list-ip-addresses -g crazy-rabbits-rg -n crazy-rabbits-vm-k8s-07 -o table
VirtualMachine PrivateIPAddresses
crazy-rabbits-vm-k8s-07 10.0.3.10
$ az vm show -g crazy-rabbits-rg -n crazy-rabbits-vm-k8s-07 --query privateIps -d --out tsv
10.0.3.10
I get a whole list of IP addresses when using "--query privateIps -d --out tsv" against an AKS cluster node:
"172.16.107.35,172.16.107.36,172.16.107.37,172.16.107.38,172.16.107.39,172.16.107.40,172.16.107.41,172.16.107.42,172.16.107.43,172.16.107.44,172.16.107.45,172.16.107.46,172.16.107.47,172.16.107.48,172.16.107.49,172.16.107.50,172.16.107.51,172.16.107.52,172.16.107.53,172.16.107.54,172.16.107.55,172.16.107.56,172.16.107.57,172.16.107.58,172.16.107.59,172.16.107.60,172.16.107.61,172.16.107.62,172.16.107.63,172.16.107.64,172.16.107.65"
Is there a way to get just the address that applies to this?
Most helpful comment
sorry I should have been more specific. I just want to return the ipAddress itself as a string as I'm passing that to the --servers parameter to create an Application Gateway.
I've tried various combinations of...
az vm show -g $RgName -n Vm1 --query "{privateIps}" --out tsv
az vm show -g $RgName -n Vm1 --query "{ipConfigurations:privateIpAddress}" --out tsv
etc.