How to programatically create and configure a digital ocean droplet using API and Ansible?

Posted July 26, 2019 3.6k views
DigitalOceanPythonAPIAnsibleUbuntu 18.04Automated Setups

We have a working ansible script which we use to configure a droplet after it is manually provisioned.

We are now planning to ditch manual process and automate creation and destruction of do instances using a python script. This is the workflow I have in mind.

  1. Create a droplet, with all required software and save it as a snapshot
  2. When needed spin up a droplet based on the snapshot using python api from a script
  3. Using Ansible make config changes to the snapshot, from the same script

The idea is to have fully automatic creation of instances, from a python script, with all software installed and all configuration done.

My question is how to do the step 3?


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.

Submit an Answer
2 answers

Have you checked to apply the aciconfigsnapshot module?


Can you please clarify on what changes exactly do you need to make?

Here’s the documentation regarding the Snapshots API functionality:

For example if you would like to create a volume snapshot you could just use this curl request:

curl -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582' -d '{"name":"big-data-snapshot1475261774", "tags":["aninterestingtag"]}' "" 

The output that you would get should look something like this:

  "snapshot": {
    "id": "8fa70202-873f-11e6-8b68-000f533176b1",
    "name": "big-data-snapshot1475261774",
    "regions": [
    "created_at": "2016-09-30T18:56:14Z",
    "resource_id": "82a48a18-873f-11e6-96bf-000f53315a41",
    "resource_type": "volume",
    "min_disk_size": 10,
    "size_gigabytes": 0,
    "tags": [

Hope that this helps!