{"record":{"id":"124ede7a7e180063","repo":"hashicorp/vagrant","slug":"cloud-init-command-cmd-failed-on-guest-gue","errorCode":null,"errorMessage":"cloud init command '%{cmd}' failed on guest '%{guest_name}'.","messagePattern":"cloud init command '%(.+?)' failed on guest '%(.+?)'\\.","errorType":"exception","errorClass":"Vagrant::Errors::CloudInitCommandFailed","httpStatus":null,"severity":"error","filePath":"lib/vagrant/action/builtin/cloud_init_wait.rb","lineNumber":38,"sourceCode":"\n            @logger.info(\"Checking cloud-init sentinel file...\")\n            if sentinel_path.file?\n              contents = sentinel_path.read.chomp\n              if machine.id.to_s == contents\n                @logger.info(\"Sentinel found for cloud-init, skipping\")\n                throw :complete\n              end\n              @logger.debug(\"Found stale sentinel file, removing... (#{machine.id} != #{contents})\")\n              sentinel_path.unlink\n            end\n\n            cloud_init_wait_cmd = \"cloud-init status --wait\"\n            if !machine.config.vm.cloud_init_configs.empty?\n              if machine.communicate.test(\"command -v cloud-init\")\n                env[:ui].output(I18n.t(\"vagrant.cloud_init_waiting\"))\n                result = machine.communicate.sudo(cloud_init_wait_cmd, error_check: false)\n                if result != 0\n                  raise Vagrant::Errors::CloudInitCommandFailed, cmd: cloud_init_wait_cmd, guest_name: machine.name\n                end\n              else\n                raise Vagrant::Errors::CloudInitNotFound, guest_name: machine.name\n              end\n            end\n            # Write sentinel path\n            sentinel_path.write(machine.id.to_s)\n          end\n\n          @app.call(env)\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":20,"sourceCodeEnd":54,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/action/builtin/cloud_init_wait.rb#L20-L54","documentation":"During boot, the cloud_init_wait middleware runs `cloud-init status --wait` via sudo in the guest (error_check disabled). A non-zero exit code means cloud-init itself executed and reported failure, so Vagrant raises CloudInitCommandFailed with the command and guest name. The root cause is almost always in the user_data/meta_data you shipped, not in Vagrant.","triggerScenarios":"`vagrant up`/`vagrant reload` with vm.cloud_init_configs non-empty, cloud-init present in the guest, and `sudo cloud-init status --wait` exiting non-zero (lib/vagrant/action/builtin/cloud_init_wait.rb:34-39). Typical causes: user_data that is not valid #cloud-config YAML, failing runcmd/write_files modules, or package installation failures inside cloud-init.","commonSituations":"Malformed user_data (missing `#cloud-config` header, tabs, bad indentation); write_files with wrong permissions; apt/yum failures from network issues; conflicting cloud-init modules; slow mirrors causing module errors.","solutions":["Inspect the guest logs: `vagrant ssh -c 'cloud-init status --long'` and `vagrant ssh -c 'sudo tail -n 100 /var/log/cloud-init.log /var/log/cloud-init-output.log'`.","Fix the user_data identified in the logs (usually a YAML/schema error), then `vagrant destroy && vagrant up` so the corrected NoCloud ISO is regenerated.","Validate the config before re-upping: `cloud-init schema --config-file user-data` on any machine with cloud-init installed.","If the failure is a transient network/package error, fix connectivity and re-run cloud-init in the guest (`sudo cloud-init clean --logs && sudo reboot`) or just recreate the VM."],"exampleFix":"# before (invalid user_data: missing #cloud-config header)\nconfig.vm.cloud_init do |cloud_init|\n  cloud_init.user_data = \"packages:\\n  - htop\\n\"\nend\n\n# after\nconfig.vm.cloud_init do |cloud_init|\n  cloud_init.user_data = \"#cloud-config\\npackages:\\n  - htop\\n\"\nend","handlingStrategy":"validation","validationCode":"# Validate user_data before `vagrant up`\n# (a) at minimum, parse the YAML\nruby -ryaml -e 'YAML.load_file(\"user-data\") or raise \"empty\"' 2>/dev/null || echo \"invalid YAML\"\n# (b) with cloud-init installed: schema check\ngrep -q '^#cloud-config' user-data && cloud-init schema --config-file user-data && echo OK","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Start every user_data file with the `#cloud-config` header and validate with `cloud-init schema --config-file` before upping.","Keep a known-good minimal user_data and add directives incrementally so the failing module is obvious.","In CI, run `vagrant ssh -c 'cloud-init status --wait'` after up to surface cloud-init failures as a clear step with logs attached."],"tags":["vagrant","cloud-init","provisioning","boot"],"backgroundTag":"cloud-init-failed","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}