• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Vagrant
  • Install
  • Intro
  • Tutorials
  • Documentation
  • Vagrant Cloud
  • Try Cloud(opens in new tab)
  • Sign up
Vagrant Home

Documentation

Skip to main content
  • Documentation
    • Overview
    • Configuration
    • Usage
  • Multi-Machine

  • Vagrant Cloud

  • Resources

  • Tutorial Library
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  1. Developer
  2. Vagrant
  3. Documentation
  4. Cloud-Init
  5. Usage
  • Vagrant
  • v2.3.3
  • v2.3.2
  • v2.3.1
  • v2.3.0
  • v2.2.19
  • v2.2.18
  • v2.2.17
  • v2.2.16
  • v2.2.15
  • v2.2.14
  • v2.2.13
  • v2.2.12
  • v2.2.11
  • v2.2.10

ยปBasic Usage

Warning! This feature is experimental and may break or change in between releases. Use at your own risk. It currently is not officially supported or functional.

This feature currently requires the experimental flag to be used. To explicitly enable this feature, you can set the experimental flag to:

VAGRANT_EXPERIMENTAL="cloud_init,disks"

Please note that VAGRANT_EXPERIMENTAL is an environment variable. For more information about this flag visit the Experimental docs page for more info. Without this flag enabled, any cloud-init configs defined will not be configured.

Also note that the examples below use the VirtualBox provider, which is the current supported provider for this feature.

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:

# 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:

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
Edit this page on GitHub

On this page

  1. Basic Usage
  2. Basic Examples
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)