Report this

What is the reason for this report?

Droplet create - user data not executed

Posted on April 30, 2020

I’m trying to create a droplet and adding a code (in this case a hardcoded ‘saraza’) to a file for later purposes. This code will change from droplet to droplet so I needed parametrized. But when I execute this, no file is created in my droplet. I’ve seen another questions that said that this is the way to do this.

curl -v -X POST “https://api.digitalocean.com/v2/droplets
-d’{“name”:“My-Droplet”,“region”:“nyc3”,“size”:“s-1vcpu-1gb”,“image”:“ubuntu-18-04-x64”, “ssh_keys”: [“‘$SSH_PUBLIC_KEY_DO_FORMAT’”], “user_data”: "`#cloud-config runcmd:

  • echo saraza > ~/file.txt`"}’
    -H “Authorization: Bearer $DO_API_TOKEN”
    -H “Content-Type: application/json”)

Thanks for the help



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, @dseidler

I will recommend you to check our official docs for the User Data:

https://www.digitalocean.com/docs/droplets/resources/metadata/#about-user-data

As shown in the example in the article you can simply create a bash script that will execute the command you want after the droplet creation.

curl -X POST "https://api.digitalocean.com/v2/droplets" \
      -d’{“name”:“My-Droplet”,“region”:“nyc3”,“size”:“s-1vcpu-1gb”,“image”:“ubuntu-18-04-x64”,"user_data":
"#!/bin/bash

echo saraza > ~/file.txt
      -H "Authorization: Bearer $TOKEN" \
      -H "Content-Type: application/json"

You can try with the example above and see if it works for you.

Note: You can also check the output logs and see what happened when the startup script tried to run the user-data

The log is located here:

/var/log/cloud-init-output.log

Let me know how it goes.

Regards, Alex

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.