diff --git a/systemd/cloud-init-generator.tmpl b/systemd/cloud-init-generator.tmpl index 5999fc5d2631..3c9ca16958cd 100644 --- a/systemd/cloud-init-generator.tmpl +++ b/systemd/cloud-init-generator.tmpl @@ -64,8 +64,12 @@ main() { ds=$? debug 1 "ds-identify rc=$ds" - if [ "$ds" = "1" ]; then - debug 1 "cloud-init is enabled but no datasource found, disabling" + if [ "$ds" = "1" -o "$ds" = "2" ]; then + if [ "$ds" = "1" ]; then + debug 1 "cloud-init is enabled but no datasource found, disabling" + else + debug 1 "cloud-init is disabled by kernel commandline or etc_file" + fi if [ -f "$link_path" ]; then if rm -f "$link_path"; then debug 1 "disabled. removed existing $link_path" diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py index 66dae60e4a1b..200c488c6517 100644 --- a/tests/unittests/test_ds_identify.py +++ b/tests/unittests/test_ds_identify.py @@ -329,6 +329,10 @@ def write_mock(data): "ret": 1, "err": "No dmidecode program. ERROR.", }, + { + "name": "is_disabled", + "ret": 1, + }, { "name": "get_kenv_field", "ret": 1, diff --git a/tools/ds-identify b/tools/ds-identify index 8b5229d8ebf4..051bc2376a54 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -1039,6 +1039,23 @@ has_ovf_cdrom() { return 1 } +is_disabled() { + if [ -f /etc/cloud/cloud-init.disabled ]; then + debug 1 "disabled by marker file /etc/cloud-init.disabled" + return 0 + fi + if [ "${KERNEL_CMDLINE:-}" = "cloud-init=disabled" ]; then + debug 1 "disabled by KERNEL_CMDLINE environment variable" + return 0 + fi + case "$DI_KERNEL_CMDLINE" in + *cloud-init=disabled*) + debug 1 "disabled by kernel command line cloud-init=disabled" + return 0 + esac + return 1 +} + dscheck_OVF() { check_seed_dir ovf ovf-env.xml && return "${DS_FOUND}" @@ -1517,10 +1534,7 @@ dscheck_VMware() { } collect_info() { - read_uname_info - read_virt read_pid1_product_name - read_kernel_cmdline read_config read_datasource_list read_dmi_sys_vendor @@ -1795,6 +1809,12 @@ _main() { read_uptime debug 1 "[up ${_RET}s]" "ds-identify $*" + read_uname_info + read_virt + read_kernel_cmdline + if is_disabled; then + return 2 + fi collect_info if [ "$DI_LOG" = "stderr" ]; then