Question
Droplet Meta Data not being passed
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 serverpilot-installer.py https://download.serverpilot.io/serverpilot-installer.py && \
sudo python serverpilot-installer.py \
--server-id=$SERVERID
--server-apikey=$SERVERAPIKEY
";
// 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!
–Constantine
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.
×
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 http://169.254.169.254/metadata/v1/user-data 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 http://169.254.169.254/metadata/v1/user-data” but it does not get executed on droplet creation.
Same problem is observed. I could verify that curl http://169.254.169.254/metadata/v1/user-data 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 phpDont 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:
Same result with:
Your help would be really apreciated,
Thanks in advance,
Franck
Why single quotes on
EOD
, pls remove them and write it down as i wrote it and try like that @didakticiel