Skip to main content
# Ansible Droplet
[![Travis](https://img.shields.io/travis/FlorianKempenich/ansible-droplet.svg)](https://travis-ci.org/FlorianKempenich/ansible-droplet) [![PyPI](https://img.shields.io/pypi/v/ansible-droplet.svg)](https://pypi.org/project/ansible-droplet/)

`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](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#generating-a-new-ssh-key)
1. Make sure you have a **Digital Ocean API token**, or [generate one](https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-api-v2)
1. **Store in a file** the Digital Ocean API token in clear<sup>[1](#f1)</sup>
1. Note down:
* _Path_ to your **ssh public key**
* _Path_ to the file containing the **Digital Ocean API token**
1. 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 supported<sup>[2](#f2)</sup>:
* **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](https://github.com/FlorianKempenich/ansible-droplet/tree/master/ansible_droplet/ansible/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 _virtualenvs_**<sup>[3](#f3)</sup>


---
1. <span id="f1"></span>Yes, this is a security concern. Feel free to open a pull request.
2. <span id="f2"></span>For now, the addition of new droplet specs is not supported. Again, pull requests are welcome :)
3. <span id="f3"></span>This is not optimal... You know what to do ;)

Release files for ansible-droplet 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansible-droplet 0.5.0
File Size Uploaded
ansible-droplet-0.5.0.tar.gz 11.6 kB Details

Release files / ansible-droplet-0.5.0.tar.gz

Download URL ansible-droplet-0.5.0.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
50dd95038d237776d01212fac6f5d4f8ae4e2d203a257a70ae301afd41d80b94
BLAKE2b-256 checksum
How to use checksums
22f16d4291f6c320cc896d65e7d11d2d675fe5ffbfb7ece96977b4531f2ce6b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.14

Release history Release notifications | RSS feed

This release

0.5.0 This release

1 release file

0.4.7

1 release file

0.4.6

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0.4

1 release file

0.3.0.3

1 release file

0.3.0.2

1 release file

0.3.0.1

1 release file

0.3

1 release file

0.2.5.1

1 release file

0.2.5.0

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page