cloud.cfg and cloud-config — Instance initialization
Cloud-init combines system configuration (/etc/cloud/cloud.cfg and cloud.cfg.d snippets) with datasource-provided metadata and user data. User-data cloud-config is YAML with a #cloud-config header; system cloud.cfg also defines the module lists for initialization stages. users selects account setup, packages selects installation, and cloud_init_modules, cloud_config_modules and cloud_final_modules govern stage membership. Merge behavior depends on source and merge strategy; list values are not necessarily simply appended. Module frequency and instance identity determine whether work repeats; not every module is idempotent. Keep secrets out of image and user-data examples. The sample is a small user-data schema check, not a complete replacement cloud.cfg. Use cloud-init schema with the installed version, then test a new authorized disposable instance and inspect status and logs. Never run cloud-init clean or re-run provisioning stages just to validate a candidate. Restore the image or instance from a known-good snapshot if initialization fails.
Formal Syntax & Structure
#cloud-configpackage_update: falsepackages: []Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| users | directive or field | Account definitions |
| packages | directive or field | Package installation requests |
| cloud_init_modules | directive or field | Initialization stage modules |
| cloud_config_modules | directive or field | Configuration stage modules |
| cloud_final_modules | directive or field | Final stage modules |
Return Value
Schema check status, not proof of successful boot.
Working Example
set -eud=$(mktemp -d)trap 'rm -rf -- "$d"' EXITcat > "$d/user-data.yaml" <<'EOF'#cloud-configpackage_update: falsepackages: []EOFcloud-init schema -c "$d/user-data.yaml"