Back to Vagrant

Basic Usage

website/content/docs/cloud-init/usage.mdx

2.4.91.9 KB
Original Source

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

[!IMPORTANT]
Documentation Update: Product documentation previously located in /website has moved to the hashicorp/web-unified-docs repository, where all product documentation is now centralized. Please make contributions directly to web-unified-docs, since changes to /website in this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

Basic Usage

Below are some very simple examples of how to use Vagrant Cloud-Init with the VirtualBox provider.

For more detailed information about these config values and how to use cloud-init, please read the official documentation for cloud-init.

Basic Examples

A cloud_init config can be defined as a "hash" of key values, or as a block. Below are two examples of this for defining a cloud_init config:

ruby
# Simplified form
config.vm.cloud_init content_type: "text/x-shellscript", path: "./foo/bar.sh"

# Block form
config.vm.cloud_init do |cloud_init|
  cloud_init.content_type = "text/cloud-config"
  cloud_init.inline = <<-EOF
    package_update: true
    packages:
      - nginx
  EOF
end

The first part will be read from a local file ./foo/bar, and the second part will be attached using the inline content. Both "block" and "hash" forms are supported, and should work interchangeably.

Individual machines may have their own cloud-init data:

ruby
config.vm.define "web" do |web|
  web.vm.cloud_init content_type: "text/cloud-config",
    inline: <<-EOF
      package_update: true
      packages:
        - nginx
    EOF
  end
end

config.vm.define "db" do |db|
  db.vm.cloud_init content_type: "text/cloud-config",
    inline: <<-EOF
      package_update: true
      packages:
        - postgresql
    EOF
end