danielmd
By:
danielmd

What is Enable User Data?

October 29, 2014 26.9k views

What does the Enable User Data option provide? I don't understand the meaning.

1 comment
  • Selecting Enable User Data allows you to input a Bash script to customize your server during provisioning. In theory, this could do anything you want, but most might use it to run a repo update/upgrade or install some software automatically. The real power comes when interacting via the API, as you could bring servers up and down passing scripts each time to setup the server as needed.

    More info here: https://www.digitalocean.com/community/tutorials/an-introduction-to-droplet-metadata

    Update CloudInit link and conclusion Metadata is a service provided to DigitalOcean droplets that allows a droplet to access data about itself, i.e. its metadata. Examples of available droplet metadata include user-provided user data, droplet ID, data center region,...
1 Answer

The Enable User Data setting allows you to pass arbitrary data into the user-data key of the DigitalOcean Metadata service. You can then retrieve that data on your droplet by running:

curl -w "\n" http://169.254.169.254/metadata/v1/user-data

On it's own, that's not very exciting but it allows for some interesting things when you combine it with a program called CloudInit that is installed by default on Ubuntu 14.04 and up as well as CentOS 7. It processes the user data and runs it on the droplet. For instance, you could put a bash script in there and it will be run on first boot. People use this to do a lot of initial set up on their droplets like installing packages. For more info, see this tutorial:

Update CloudInit link and conclusion Metadata is a service provided to DigitalOcean droplets that allows a droplet to access data about itself, i.e. its metadata. Examples of available droplet metadata include user-provided user data, droplet ID, data center region,...
  • Letting you run programs and scripts while booting server? Isnt it unsecure? Lots of opportunities for viruses i suppose.

    Correct me if im wrong please

  • @Aventoria It will only run what the user provides.

    This is a powerful way to do initial configuration of a server. Check out the tutorial linked above for more info. An Introduction to Cloud-Config Scripting will also give you a good idea how this feature is generally used.

    The DigitalOcean metadata service includes a field called "user-data", which can be used to specify a script that will be run as your server is brought online. The CloudInit program, which runs these scripts, can process a special script type called "cloud-config". In this guide, we'll explore how to create cloud-config files and the best ways to leverage their power.
Have another answer? Share your knowledge.