don't worry, it's probably fine

DigitalOcean Codes for Ansible Provisioning

29 Jul 2014


I’ve been using Ansible to provision DigitalOcean instances using the digital_ocean module, which was going well until it became apparent that I didn’t need the slugs for provisioning (e.g. size: 512mb or region: lon1), but a numeric index. After digging around (admittedly not very far) I could only find the codes exposed via the v1 API. Since you can import vars files in Ansible, I’ve written a small script to turn the API responses for images, regions, and sizes into usable variable names for easy importing.

It generates a yaml file which looks like this:

# regions
do_regions_sfo1: 3
# sizes
do_sizes_512mb: 66
# images
do_images_centos-5-8-x64: 1601

The source is available here with a version that I pulled today. Just drop this file into your vars, import with

  - vars/do_codes.yml

and use as below

    - name: Create instance
      local_action: digital_ocean
        size_id="{{ do_sizes_512mb }}"
        region_id="{{ do_regions_lon1 }}"
        image_id="{{ do_images_node }}"

It’s not a perfect solution, but this should do until Ansible starts supporting slugs instead of codes in their digital_ocean module.