Skip to content

Instantly share code, notes, and snippets.

@marsam
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save marsam/9060835 to your computer and use it in GitHub Desktop.

Select an option

Save marsam/9060835 to your computer and use it in GitHub Desktop.
Create new droplet ansible

Create new droplet:

$ pip install -U ansible dopy
$ ansible-playbook newdroplet.yml
---
- name: Create new droplet
hosts: 127.0.0.1
connection: local
sudo: no
vars:
name: motoko
size_id: 66 # 1 CPU, 512MB, 20GB
image_id: 350424 # Arch Linux 2013.05 x64
region_id: 2 # Amsterdam 2
api_key: "{{ lookup('env','DO_API_KEY') }}"
client_id: "{{ lookup('env','DO_CLIENT_ID') }}"
ssh_pub_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
ssh_key_name: "mykey"
tasks:
- name: Add my ssh public key
register: ssh_key
digital_ocean: >
state=present
command=ssh
name={{ ssh_key_name }}
api_key={{ api_key }}
client_id={{ client_id }}
ssh_pub_key="{{ ssh_pub_key }}"
- name: Create DigitalOcean droplet
register: droplet
digital_ocean: >
state=active
private_networking=yes
unique_name=yes
ssh_key_ids="{{ ssh_key.ssh_key.id }}"
name={{ name }}
api_key={{ api_key }}
client_id={{ client_id }}
size_id={{ size_id }}
image_id={{ image_id }}
region_id={{ region_id }}
- debug: msg="ID is {{ droplet.droplet.id }}"
- debug: msg="IP is {{ droplet.droplet.ip_address }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment