By Justin Noor
Cloud config is not working at all from the command line with APIv2 on Ubuntu 18.04. Anyone experience this? Even this simple script doesn’t work:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $MY_TOKEN" -d '{
"name": "myserver",
"region": "sfo2",
"size": "s-1vcpu-1gb",
"image": "ubuntu-18-04-x64",
"ssh_keys": ["XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"],
"user_data": "#cloud-config
write_files:
- content |
This is a test file
path: /etc/cloud-config-test
permissions: '0600'
owner: root:root"
}' "https://api.digitalocean.com/v2/droplets"
At first glance, examining /var/log/cloud-init.log, and /var/log/cloud-init-output.log, reveals nothing about the ‘user-data:#cloud-config’ entry in my APIv2 POST. Due to their size I left them out. I would be happy to share them if needed.
Thanks
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!
Heya,
it seems that the issue might be related to the formatting of your user_data field. Please make sure you have proper formatting and indentation in your cloud-config YAML file.
Here’s a corrected version of your script:
- curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $MY_TOKEN" -d '{
- "name": "myserver",
- "region": "sfo2",
- "size": "s-1vcpu-1gb",
- "image": "ubuntu-18-04-x64",
- "ssh_keys": ["XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"],
- "user_data":
- "#cloud-config\n
- write_files:\n
- - content: |\n
- This is a test file\n
- path: /etc/cloud-config-test\n
- permissions: '\''0600'\''\n
- owner: root:root"
- }' "https://api.digitalocean.com/v2/droplets"
Please ensure you replace $MY_TOKEN and the ssh_keys_values with your actual API token and SSH key fingerprint.
If you still encounter issues, we suggest checking your log files and sharing relevant parts for further assistance. For more information on cloud-config, you can read our tutorial on the basics of cloud-config scripting.
Hope that this helps!
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.