ansible-droplet

A cli to Create / Destroy DigitalOcean Droplets


Keywords
digitalocean, digital, ocean, droplet, ansible, ssh, provision
License
MIT
Install
pip install ansible-droplet==0.5.0

Documentation

Ansible Droplet

Travis PyPI

ansible-droplet is a cli tool to easily create ready-to-use droplets on Digital Ocean.

  • Create ready-to-use Ubuntu Droplet on Digital Ocean
  • One simple command: ansible-droplet create my_droplet
  • Access it directly via its name:
    • SSH: ssh my_droplet
    • Ansible: - hosts: my_droplet
  • And more:
    • New sudo user automatically created
    • Swap added (configurable)
    • DigitalOcean advanced metrics enabled
    • glances server running to monitor the Droplet from outside

Installation

Important Note: For now only python 2 is supported

pip install ansible-droplet

Use a virtualenv or install with pip install ansible-droplet --user


Usage

One time setup

Before using the tool, a simple one-time-setup must be done.

  1. Make sure you have a ssh public key, or generate one
  2. Make sure you have a Digital Ocean API token, or generate one
  3. Store in a file the Digital Ocean API token in clear1
  4. Note down:
    • Path to your ssh public key
    • Path to the file containing the Digital Ocean API token
  5. Run ansible-droplet config see below for more detail on the config parameters

Create

ansible-droplet create my_droplet
Creation process
  • Create a new Droplet on your Ditigal Ocean Account
  • Set it up with: Swap, new sudo user, glances server
  • Create a SSH entry in your ~/.ssh/config to be able to ssh directly with its name: ssh my_droplet
  • Create a ansible inventory entry in ~/.ansible-droplet-inventory

Destroy

ansible-droplet destroy my_droplet
Destruction process
  • Destroy the Droplet from your Ditigal Ocean Account
  • Remove the SSH entry from your ~/.ssh/config to be able to ssh directly with its name: ssh my_droplet
  • Remove the ansible inventory entry from ~/.ansible-droplet-inventory

Advanced Usage

Config parameters

When running ansible-droplet config a couple of parameters must be provided:

  • Path to SSH key:
    No brainer, the path to your SSH public key.
    Default: ~/.ssh/id_rsa.pub

  • Name of SSH key on Digital Ocean:
    To prevent uploading the public keys each time, Digital Ocean offers to store them under a name. It can be anything.
    Default: Main SSH Key

  • Path to Ditigal Ocean token:
    The path to the file containing your Digital Ocean token in plain text.
    No defaults

  • User on Droplet - Username:
    Username for the sudo user being created on the Droplet.
    No defaults

  • User on Droplet - Default Password: Default password for the sudo user being created on the Droplet.
    No defaults
    Do not forget to change it after the first login!

Droplet specs

You can specify the droplet size and specs when creating a new droplet.
Simply list it after the droplet name:

ansible-droplet create my_droplet SPEC_NAME

For now, only 3 specs are supported2:

  • Micro
    • size: "512mb"
    • region: "fra1"
    • image: "ubuntu-16-04-x64"
    • swap: "4GiB"
  • Mini
    • size: "1gb"
    • region: "fra1"
    • image: "ubuntu-16-04-x64"
    • swap: "4GiB"
  • Power
    • size: "4gb"
    • region: "fra1"
    • image: "ubuntu-16-04-x64"
    • swap: "4GiB"

The list of specification are stored on the repository: Droplet Specs

Ansible Droplet Inventory

It is possible to access the Droplet from any other ansible playbook via its name:

- hosts: my_droplet

For that purpose the file ~/.ansible-droplet-inventory is created.
~/.ansible-droplet-inventory contains ansible inventory entries for each Droplet created with the ansible-droplet tool.

To use the droplet in a playbook, either:

  • Point your inventory to the ~/.ansible-droplet-inventory file
  • Point your inventory to a directory containing a symlink to the ~/.ansible-droplet-inventory file

From there you can reference the Droplet directly by name.

Multiple configuration - Multiple Digital Ocean accounts

You can use multiple configurations to support:

  • Multiple DigitalOcean accounts
  • Multiple SHH Keys
  • Multiple default user/password

The configuration generated by ansible-droplet config is kept in the installation directory.

To allow multiple configs, simply install multiple versions of ansible-droplet in different virtualenvs3


  1. Yes, this is a security concern. Feel free to open a pull request.
  2. For now, the addition of new droplet specs is not supported. Again, pull requests are welcome :)
  3. This is not optimal... You know what to do ;)