Fix ds-identify not detecting NoCloud seed in config (SC-542)#1381
Conversation
NoCloud seed config can be defined in /etc/cloud/cloud.cfg[.d]. However, ds-identify had no means of detecting this config and reported NOT FOUND. This commit allows ds-identify to detect and report it properly. LP: #1876375
| fi | ||
|
|
||
| # This is a bit hacky, but a NoCloud false positive isn't the end of the world | ||
| if check_config "NoCloud" && check_config "user-data" && check_config "meta-data"; then |
There was a problem hiding this comment.
user-data and meta-data are required seed files for NoCloud, but it looks like check_config searches /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d/* for keys with this name (am I reading that right?). Since I don't see those as keys in the doc, could you please expand on why this works?
There was a problem hiding this comment.
Yeah, this functionality needs to be documented better. I just learned of this behavior due to the bug report 😄 The only documentation is an example. The magic happens in the datasource.
For the ds-identify piece, check_config just looks for a key at any nesting of the config (thanks bash). I'm basically just assuming that if 'NoCloud', 'user-data', and 'meta-data' exist somewhere in the config, then the datasource definition is happening there. If we're wrong, we waste a few cycles in python code checking for NoCloud.
There was a problem hiding this comment.
E.g., create
/etc/cloud/cloud.cfg.d/99_ds.cfg:
datasource_list: ["NoCloud"]
datasource:
NoCloud:
user-data: |
#cloud-config
runcmd:
- echo 'hi' > /var/tmp/hi
meta-data:
instance-id: i-87018aed
local-hostname: myhost.internalThen cloud-init clean --logs --reboot and you should see those details reflected in your instance. With this branch, you shouldn't need the datasource_list line.
There was a problem hiding this comment.
Aha! Thanks. Yes this seems like something that should be documented better. I'm indifferent whether we should update the docs in this PR or a followup.
There was a problem hiding this comment.
Already in our docs tracking ticket
Proposed Commit Message
Additional Context
LP: #1876375 notes that if you specify the datasource list in a cfg file, it works, but if you don't it doesn't. It has nothing to do with the reading of the config files. If the datasource list only contains one entry (or one + None), ds-identify skips datasource detection entirely and just uses the specified datasource. https://github.com/canonical/cloud-init/blob/main/tools/ds-identify#L1793-L1798 . The problem is that ds-identify just had no means of detecting this use case.
Test Steps
Checklist: