Expose EC2 platform type in machine readable format from ds-identify
Bug #1724626 reported by
Robert C Jennings
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init (Ubuntu) |
Fix Released
|
Medium
|
Unassigned |
Bug Description
I would like to see the EC2 platform information in /run/cloud-
Also, if you have suggestions as to what cloud-init info should be appended to bug descriptions or attachments as part of bug #1724623, please comment there as the insight would be very helpful.
description: | updated |
Changed in cloud-init (Ubuntu): | |
status: | New → Confirmed |
importance: | Undecided → Medium |
To post a comment you must log in.
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",
"_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-li...