Question

Droplet user-data with new lines

Hi there,

is there a simple way to add a bigger user-data file into the string?

We have quite a few linebreaks and it is cumbersome to add those. Is there a recommended online tool to convert smth like

#!/bin/bash

add-apt-repository -y ppa:ondrej/php
apt -y update
apt -y install nginx
apt -y install jq

into “#!/bin/bash \n add-apt-repository …”

The option to add a file link at whould be great too.

user_data

and

user_data_file


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Hi there,

Yes, what you could do is to create a file and add that content into the file.

Let’s say that you’ve created a file called user-data.yml and you’ve added your script in there.

Then you could use the following curl request to spin up a new server with that user data file:

curl -X POST "https://api.digitalocean.com/v2/droplets" \
      -d'{"name":"metadata.example.com","region":"nyc3","size":"s-1vcpu-1gb","vpc_uuid":"c33931f2-a26a-4e61-b85c-4e95a2ec431b","image":"ubuntu-20-04-x64","user_data":
"'"$(cat ~/user-data.yml)"'",
      "ssh_keys":[ < SSH KEY IDs > ]}' \
      -H "Authorization: Bearer $TOKEN" \
      -H "Content-Type: application/json"

Hope that this helps!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up