How to be notified when a droplet is active after his creation

Hi ! I’m working on an automation script with the DO API and Ansible. I can create a lot of droplets but how to know if the created droplets has been active ?

The first ( naive ) approach uses the following process :

A. Create droplet with the Digital Ocean API
B. Call the API to get the created droplet informations
    1. is active ?
        yes : 
        no : go to B

In the best world, after the droplet creation, I will be notified ( like a webhoock executed when the droplet creation is finished ). Is it possible ?

Many thanks

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This is the answer from SO :

Another method would be to modify the droplet as it is created. With Digital ocean you can pass User Data, previously I have used this to configure servers automatically, here is an example.

$user_data = <<<EOD

apt-get update 
apt-get -y install apache2 
apt-get -y install php5 
apt-get -y install php5-mysql 
apt-get -y install unzip 
service apache2 restart 
cd /var/www/html 
mkdir pack 
cd pack 
wget --user {$wgetUser} --password {$wgetPass} http://x.x.x.x/pack.tar.gz
tar -xvf pack.tar.gz 
php update.php

    //Start of the droplet creation
    $data = array(

    $chDroplet = curl_init('');
    curl_setopt($chDroplet, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($chDroplet, CURLOPT_POSTFIELDS, json_encode($data)  );
    curl_setopt($chDroplet, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer '.$apiKey,
        'Content-Type: application/json',
        'Content-Length: ' . strlen(json_encode($data)),

Basically once the droplet is active it will run these commands and then download a tar.gz file from my server and execute it, you could potentially create update.php to call your server and therefore update it that the droplet is online.

So, with the User Data we can run a wget command to launch a webhook. With this solution we can have an “event based” notification.