Report this

What is the reason for this report?

Cloud config not working at all with APIv2 on Ubuntu 18.04

Posted on July 14, 2019

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!

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.

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:

  1. curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $MY_TOKEN" -d '{
  2. "name": "myserver",
  3. "region": "sfo2",
  4. "size": "s-1vcpu-1gb",
  5. "image": "ubuntu-18-04-x64",
  6. "ssh_keys": ["XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"],
  7. "user_data":
  8. "#cloud-config\n
  9. write_files:\n
  10. - content: |\n
  11. This is a test file\n
  12. path: /etc/cloud-config-test\n
  13. permissions: '\''0600'\''\n
  14. owner: root:root"
  15. }' "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!

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.