Minimally this is resolved as of cloud-init version 21.4 which surfaced a /run/cloud-init/cloud-id file which represents the unique cloud datasource type cloud-init detects:
cat /run/cloud-init/cloud-id will have the following values:
aws
azure
gce
openstack
lxd
nocloud
Note as well that cloud-init creates a symlink pointing to this file of the format:
/run/cloud-init/cloud-id-<cloud_name>
This allows scripts to easily check presence of a cloud-specific file /run/cloud-init/cloud-id-aws to indicate what platform cloud-init detected.
Note that this value will be incorrect if someone installs NoCloud datasource seed files on an Ec2 vm in /var/lib/cloud/seed/nocloud-net/(user-data|meta-data) because cloud-init will detect the NoCloud datasource before Ec2 datasource in that case.
Additional sources of flat files that can provide more context for identity of the system/platform
would be /run/cloud-init/instance-data.json which is structured configuration attributes that cloud-init reads from the datasource it detects.
instance-data.json provide versioning of generalized config variables under the v1 key of instance-data.json
Here are some examples on various clouds (again note that any cloud could have a NoCloud seed file placed in the environment that would prevent cloud-init from detecting the underlying cloud platform config on those systems):
Keep in mind as well there are additional pieces of data that are cloud-specific which give you more details about the offering, instance size etc under a top-level key in instance-data.json "ds".
On EC2 you get something like the following under 'ds'
Minimally this is resolved as of cloud-init version 21.4 which surfaced a /run/cloud- init/cloud- id file which represents the unique cloud datasource type cloud-init detects:
cat /run/cloud- init/cloud- id will have the following values:
aws
azure
gce
openstack
lxd
nocloud
Note as well that cloud-init creates a symlink pointing to this file of the format: cloud-init/ cloud-id- <cloud_ name>
/run/
This allows scripts to easily check presence of a cloud-specific file /run/cloud- init/cloud- id-aws to indicate what platform cloud-init detected.
Note that this value will be incorrect if someone installs NoCloud datasource seed files on an Ec2 vm in /var/lib/ cloud/seed/ nocloud- net/(user- data|meta- data) because cloud-init will detect the NoCloud datasource before Ec2 datasource in that case.
Additional sources of flat files that can provide more context for identity of the system/platform
would be /run/cloud- init/instance- data.json which is structured configuration attributes that cloud-init reads from the datasource it detects.
instance-data.json provide versioning of generalized config variables under the v1 key of instance-data.json
Here are some examples on various clouds (again note that any cloud could have a NoCloud seed file placed in the environment that would prevent cloud-init from detecting the underlying cloud platform config on those systems):
https:/ /hackmd. io/aAJFerDRRNao L0Q_vDRYBg
Keep in mind as well there are additional pieces of data that are cloud-specific which give you more details about the offering, instance size etc under a top-level key in instance-data.json "ds".
On EC2 you get something like the following under 'ds'
{ api_version" : "2021-03-23", identity" : { tyZone" : "us-east-2b", ducts": null, uctCodes" : null, b18025b" , 43fbf", eProductCodes" : null, 16T21:13: 36Z", b3DQEHAqCAMI. .." b18025b" , launch- index": "0", manifest- path": "(unknown)", device- mapping" : { 31-24-213. us-east- 2.compute. internal" , credentials" : { 16T21:13: 57Z" action" : "none", 43fbf", life-cycle" : "on-demand", 31-24-213. us-east- 2.compute. internal" , 4b:ae:c3: f0", \"UTF-8\ "?>" 94:4b:ae: c3:f0": { device- number" : "0", interface- id": "eni-08d6bc9285 7ee79ba" , ipv4-associatio ns": {
"3.17.151. 217": "172.31.24.213" local-hostname" : "ip-172- 31-24-213. us-east- 2.compute. internal" , local-ipv4s" : "172.31.24.213", 4b:ae:c3: f0", public- hostname" : "ec2-3- X-Y-217. us-east- 2.compute. amazonaws. com", public- ipv4s": "3.X.Y.217", security- group-ids" : "sg-08016df3e94 8f9b1f" , security- groups" : "launch-wizard-7", 0eeece021217b39 ed", subnet- ipv4-cidr- block": "172.31.16.0/20", c1d6593" , vpc-ipv4- cidr-block" : "172.31.0.0/16", vpc-ipv4- cidr-blocks" : "172.31.0.0/16" y-zone" : "us-east-2b", y-zone- id": "use2-az2", hostname" : "ec2-3- 17-151- 217.us- east-2. compute. amazonaws. com", AAAADAQABAAABAQ C..." a13fa", groups" : "launch-wizard-7",
"_doc": "EXPERIMENTAL: The structure and format of content scoped under the 'ds' key may change in subsequent releases of cloud-init.",
"_metadata_
"dynamic": {
"instance-
"document": {
"accountId": "329910648999",
"architecture": "x86_64",
"availabili
"billingPro
"devpayProd
"imageId": "ami-0283a57753
"instanceId": "i-0ecd5e14298b
"instanceType": "t2.micro",
"kernelId": null,
"marketplac
"pendingTime": "2022-12-
"privateIp": "172.31.24.213",
"ramdiskId": null,
"region": "us-east-2",
"version": "2017-09-30"
},
"pkcs7": [
"MIAGCSqGSI
],
"rsa2048": [
"MIAGCS..."
],
"signature": [
"Qk99HHJxS..."
]
}
},
"meta-data": {
"ami-id": "ami-0283a57753
"ami-
"ami-
"block-
"ami": "/dev/sda1",
"ephemeral0": "sdb",
"ephemeral1": "sdc",
"root": "/dev/sda1"
},
"events": {
"maintenance": {
"history": "[]",
"scheduled": "[]"
}
},
"hostname": "ip-172-
"identity-
"ec2": {
"info": {
"AccountId": "32991064...",
"Code": "Success",
"LastUpdated": "2022-12-
}
}
},
"instance-
"instance-id": "i-0ecd5e14298b
"instance-
"instance-type": "t2.micro",
"local-hostname": "ip-172-
"local-ipv4": "172.31.24.213",
"mac": "06:94:
"metrics": {
"vhostmd": "<?xml version=\"1.0\" encoding=
},
"network": {
"interfaces": {
"macs": {
"06:
"
"
"
},
"
"
"mac": "06:94:
"owner-id": "329910648901",
"
"
"
"
"subnet-id": "subnet-
"
"vpc-id": "vpc-0f7d68c4a9
"
"
}
}
}
},
"placement": {
"availabilit
"availabilit
"region": "us-east-2"
},
"profile": "default-hvm",
"public-
"public-ipv4": "3.17.151.217",
"public-keys": {
"sles": [
"ssh-rsa AAAAB3NzaC1yc2E
]
},
"reservation-id": "r-0949782d2698
"security-
"services": {
"domain": "amazonaws.com",
"partition": "aws"
}
}
}