Droplet Meta Data not being passed

November 17, 2014 3.5k views

Using DO's api v.2, attempting to create droplets and pass userdata however the userdata isnt being recognized.

Currently have two functions, first function creates a server on serverpilot, returning the $SERVERID & $SERVERAPIKEY and passing them into a callback function, which creates the DigitalOcean droplet passing in the user_data to run the server pilot installer, and thats where this fails.

Below is a snippet of my code ( Unfortunately cant provide full code base - but problem lies within user_data nonetheless ). Both server vars are accessible however running this only creates the server on server pilots side and the droplet, however the installer never runs.

$userData = "#!/bin/bash
    (test -e /usr/bin/wget || (sudo apt-get update && sudo apt-get -y install wget)) && \
    sudo wget -nv -O && \
    sudo python \

// create new droplet, connect to serverpilot, run installer
$data = array(
    'name'               => $appName,
    'region'             => 'nyc3',
    'size'               => '512mb',
    'image'              => 'ubuntu-14-04-x64',
    'user_data'          => $userData

Any ideas? Hope to hear from you guys soon!


  • On the server, you can run the following to see what is actually being passed to the user_data


    That should help debug the issue.

  • I am also facing an error with user_data. After droplet creation nginx is not installed.
    $userData = "#!/bin/bash
    apt-get install nginx -y";

    when i check with curl on server it shows #!/bin/bash
    apt-get install nginx -y

    For passing the data to the api i use this code below
    $data = array("name" => "NewDroplet", "region" => "ams3", "size" => "512mb", "image" => "ubuntu-14-04-x64", "user_data" => $userData);

    I am new to coding with api :-)
    I dont know what i am doing wrong.

  • I have the exact same problem. Did you ever find a solution?

    My user-data is visible in "curl" but it does not get executed on droplet creation.

  • Same problem is observed. I could verify that curl return the bash script which we passed through API. But the bash script does not get executed on droplet creation.

    Anyone got it working?

  • This isn't working for me either? Does this work for anybody? I'm using the YAML version FWIW.

  • I know its been couple of years, but since i ended up here someone else might as well
    user_data is required to be a plain text, and within quotes you also included new lines \n and tabs \t in that string, so what you ended up sending was malformed.
    You can also read user_data from a file, or use smth like in php

    This is your string
       In exactly this format
    $userData = 
    (test -e /usr/bin/wget \
    || (sudo apt-get update && sudo apt-get -y install wget)) \
    && sudo wget -nv -O \
    && sudo python \

    Dont mind the reformat i did, its only to be more readable

  • Hello @ikristic thanks for the help here again, I tried to follow your indication, but I still end up with a non connected server, here is what I used:

    $user_data = <<<'EOD'
    (test -e /usr/bin/wget \
    || (sudo apt-get update && sudo apt-get -y install wget)) \
    && sudo wget -nv -O \
    && sudo python \
            --server-id=$dataid \

    Same result with:

    $user_data = <<<'EOD'
        sudo apt-get update && sudo apt-get -y install ca-certificates wget && \
        sudo wget -nv -O serverpilot-installer && \
        sudo sh serverpilot-installer \
            --server-id=$dataid \

    Your help would be really apreciated,
    Thanks in advance,


  • Why single quotes on EOD, pls remove them and write it down as i wrote it and try like that @didakticiel

2 Answers

@asb, Everytime I attempy to run that curl command for user-data pointing to my droplet ip, i get an error - failed to connect port 80: Connection Refused.

Have another answer? Share your knowledge.