Question

How do you script a custom droplet?

Posted February 12, 2015 8.3k views

I’d like to be able to write some scripts to completely automate the creation of WordPress droplets on Ubuntu Server. But, I’d like customized WordPress droplets that are not currently offered in the Digital Ocean droplet creation UI.

For example…I’d like the WordPress droplets to run on Nginx on Ubuntu instead of Apache. The Digital Ocean WordPress application runs on Apache while the LEMP application install does not include WordPress.

Neither instance has a firewall enabled - which Digital Ocean does recommend doing once the droplet is created.

Neither instance includes Varnish, which may help with page load times.

While I can look up how to manually enable the firewall, how to install WordPress on LEMP and even how to install Varnish…I would like to be able to script all of this (starting with using the Digital Ocean v2 API) so that I can create my own web UI to start an instance of WordPress on LEMP with Varnish and the firewall configured and ready to go.

Doing this all via scripting seems like it would save a lot more time than manually setting everything up for each server.

How would you go about doing this? Are there any tutorials on scripting this sort of thing?

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.

×
3 answers

There are of course many different approaches that you could take. You could use one of the various configuration management tools like Chef, Ansible, or Fabric to script this.

Another option is to pass a script in the “user-data” when creating a new droplet. This allows you to provide a script that will run on first boot of the droplet. For more advance usages, check out these tutorials on cloud-config scripting:

by Justin Ellingwood
A cloud-config file is a special script that is used to define configuration details for your server as it is being brought online for the first time. These are often used for completing common tasks that a user would normally have to log into the server to accomplish. In this guide, we will run through how to do some initial configuration of an Ubuntu 14.04 server using a cloud-config file with our metadata service.

Internally we use scripts written to use Fabric to install and configure the software needed to create the master images for our one clicks. It’s really quite easy to start using, even if you are not very familiar with Python and will allow you to script custom deployments so you would simply launch a droplet with the OS you want to start with (either from the control panel or API) and then execute your fabric script against the new IP address.

@ryanpq Isn’t easier to just use the DigitalOcean API and create a new droplet, and then use SSH to install required programs?

Speaking of which, where can I find the formal names of the droplet OS distributions?

Submit an Answer