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:
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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.