2020-06-05 11:07:40 -07:00

73 lines
1.9 KiB
Plaintext

---
layout: docs
page_title: Vagrant Cloud-Init Usage
sidebar_title: Usage
description: Various Vagrant Cloud-Init examples
---
# 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 reqiures the experimental flag to be used. To explicitly enable this feature, you can set the experimental flag to:
```
VAGRANT_EXPERIMENTAL="cloud_init"
```
Please note that `VAGRANT_EXPERIMENTAL` is an environment variable. For more
information about this flag visit the [Experimental docs page](/docs/experimental/)
for more info. Without this flag enabled, any disks defined will not be configured.
Also note that the examples below use the VirtualBox provider, which is the current
supported providier for this feature.
Below are some very simple examples of how to use Vagrant Disks with the VirtualBox provider.
## Basic Examples
Here is an example containing two parts of user data:
```ruby
config.vm.cloud_init do |cloud_init|
cloud_init.content_type = "text/x-shellscript"
cloud_init.path = "./foo/bar.sh"
end
config.vm.cloud_init do |cloud_init|
cloud_init.content_type = "text/cloud-config"
cloud_init.inline = <<-EOF
package_update: true
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.
Individual machines may have their own cloud-init data:
```ruby
config.vm.define "web" do |web|
web.vm.cloud_init do |cloud_init|
cloud_init.content_type = "text/cloud-config",
cloud_init.inline = <<-EOF
package_update: true
packages:
- nginx
EOF
end
end
config.vm.define "db" do |db|
db.vm.cloud_init do |cloud_init|
cloud_init.content_type = "text/cloud-config",
cloud_init.inline = <<-EOF
package_update: true
packages:
- postgresql
EOF
end
```