Question
How to run user_data after droplet creation
Facing an error with user_data. After droplet creation nginx is not installed. I wanted the following coding to run on my server after droplet creation with the use user data
#!/bin/bash
apt-get -y update
apt-get -y install nginx
export HOSTNAME=$(curl -s http://169.254.169.254/metadata/v1/hostname)
export PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
echo Droplet: $HOSTNAME, IP Address: $PUBLIC_IPV4 > /usr/share/nginx/html/index.html
so i used that code in
$userData = "#!/bin/bash
apt-get -y update
apt-get -y install nginx
export HOSTNAME=$(curl -s http://169.254.169.254/metadata/v1/hostname)
export PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
echo Droplet: $HOSTNAME, IP Address: $PUBLIC_IPV4 > /usr/share/nginx/html/index.html";
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.
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.
×