bento icon indicating copy to clipboard operation
bento copied to clipboard

cloud init not working

Open ty2 opened this issue 1 month ago • 3 comments

Version

v5.0.0 (2025-10-27)

Environment

VirtualBox: 7.2.4 r170995 Host OS: Arch Linux

Scenario

Start a Vagrant VM with the official bento/ubuntu-24.04 box and create an additional user (user1) via cloud-init.

Steps to Reproduce

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-24.04"

  config.vm.provider "virtualbox" do |v|
    v.name = "node1"
    v.memory = 1024
    v.cpus = 2
  end

  config.vm.cloud_init :user_data do |cloud_init|
    cloud_init.content_type = "text/cloud-config"
    cloud_init.path = "cloud.cfg"
  end

end

cloud.cfg

#cloud-config

users:
  - name: user1
    sudo: "ALL=(ALL) NOPASSWD:ALL"
    plain_text_passwd: 123456
    lock_passwd: false

  1. Create the Vagrantfile and cloud.cfg as shown above.
  2. run vagrant up
  3. After the VM is up, run vagrant ssh
  4. Run cat /etc/passwd | grep user1 or id user1, check if user1 is exists.

Expected Result

cloud-init processes the provided cloud.cfg file during first boot and creates the user user1.

Actual Result

No user user1 is created.

ty2 avatar Dec 05 '25 14:12 ty2

Did this work previously?

Stromweld avatar Dec 05 '25 15:12 Stromweld

I'm not sure if this worked in previous versions. This was my initial attempt to use it.

ty2 avatar Dec 05 '25 21:12 ty2

cloud-init is disabled by default (cat /etc/cloud/cloud-init.disabled), so you need to enable it and then reboot.

Vagrant.configure("2") do |config|
  config.vm.cloud_init :user_data do |cloud_init|
    cloud_init.content_type =  "text/cloud-config"
    cloud_init.inline = <<-EOF
      #cloud-config
      users:
        - name: issue1655
          shell: /bin/bash
    EOF
  end

  hosts = [
    { name: "noble", box: "bento/ubuntu-24.04" },
  ]

  hosts.each do |host|
    config.vm.define host[:name] do |node|
      node.vm.box = host[:box]
      node.ssh.insert_key = true
      node.ssh.key_type = "ed25519"
      node.vm.hostname = host[:name]
      node.vm.boot_timeout = 600
      node.vm.provision "shell",
        inline: <<-SHELL
        cloud-init clean --machine-id
      SHELL
    end
  end
end

konstruktoid avatar Dec 08 '25 00:12 konstruktoid