Reputation: 101
Is there something similar to ec2metadata
in Azure virtual machines?
I need to extract data like the the public hostname or the instance id. In Amazon EC2 instances, I can do this:
$ ec2metadata --instance-id
i-3a1dcfa3
$ ec2metadata --public-hostname
ec2-54-91-124-63.compute-1.amazonaws.com
Upvotes: 6
Views: 408
Reputation: 897
It seems this question was asked a long time ago, so maybe you already found the answer. If not, though, then have you tried Azure Instance Metadata? (https://learn.microsoft.com/en-us/azure/virtual-machines/virtual-machines-instancemetadataservice-overview) You can do an http request like this:
curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-04-02"
The response looks like this:
{
"compute": {
"location": "westcentralus",
"name": "IMDSSample",
"offer": "UbuntuServer",
"osType": "Linux",
"platformFaultDomain": "0",
"platformUpdateDomain": "0",
"publisher": "Canonical",
"sku": "16.04.0-LTS",
"version": "16.04.201610200",
"vmId": "5d33a910-a7a0-4443-9f01-6a807801b29b",
"vmSize": "Standard_A1"
},
"network": {
"interface": [
{
"ipv4": {
"ipAddress": [
{
"privateIpAddress": "10.1.0.4",
"publicIpAddress": "X.X.X.X"
}
],
"subnet": [
{
"address": "10.1.0.0",
"prefix": "24"
}
]
},
"ipv6": {
"ipAddress": []
},
"macAddress": "000D3AF806EC"
}
]
}
}
Hope this helps! :)
Upvotes: 2