How to Provide User Data During Droplet Creation

DigitalOcean Droplets are Linux-based virtual machines (VMs) that run on top of virtualized hardware. Each Droplet you create is a new server you can use, either standalone or as part of a larger, cloud-based infrastructure.


Metadata is a service that allows a Droplet to access data about itself. In addition, you can use Metadata to provide user data to Droplets at creation to simplify or automate setup.

About User Data

User data is arbitrary data, most often a script, that you can supply to a Droplet during creation. If CloudInit is available on the Droplet, it will consume the user data, which it can use to perform tasks as the root user during the Droplet’s first boot.

CloudInit accepts cloud-config files or any script that can be interpreted by the new Droplet, like a Bash script. CloudInit is available on DigitalOcean’s latest Ubuntu and CentOS images. You can define user data for images that do not support CloudInit, but it will not be consumed automatically on first boot.

Providing User Data

You can provide user data to a Droplet during creation via the DigitalOcean Control Panel, the API, or doctl, the CLI client.

  • To provide user data when creating a Droplet via the DigitalOcean Control Panel, on the Droplet creation page, above the Finalize Details section, click + Advanced Options. In the section that opens, check the box next to Add Initialization scripts. Add your user data in the box that appears.

  • To provide user data when creating a Droplet via the DigitalOcean API, use the user_data field in the Droplet creation POST request.

  • To provide user data when creating a Droplet via doctl, the DigitalOcean CLI, use the --user-data or --user-data-file flags when calling doctl compute droplet create.

You cannot modify user data after a Droplet is created.

Debugging User Data

To see how a CloudInit file uses the provided user data, view the /var/log/cloud-init-output.log file:

cat /var/log/cloud-init-output.log | grep userdata

The file logs output from CloudInits so you can view any warnings, error messages, or debug information.

More Information

The metadata API allows a Droplet to access information about itself including user data, Droplet ID, datacenter region, and IP addresses.
Use the Droplet metadata service to programmatically query a Droplet for information about itself.
This tutorial explains the format and usage of cloud-config files, which are special scripts designed to be run by the cloud-initprocess for initial configuration on the first boot of a server.
digitalocean.com/community
This tutorial uses the DigitalOcean metadata service and cloud-config files to automate initial server setup for a Ubuntu Droplet.
digitalocean.com/community