DigitalOcean Codes for Ansible Provisioning

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.