Skip to content

Instantly share code, notes, and snippets.

@blocke
Created September 29, 2013 03:49
Show Gist options
  • Save blocke/6749194 to your computer and use it in GitHub Desktop.
Save blocke/6749194 to your computer and use it in GitHub Desktop.
Simple Ansible playbook for demonstrating spinning up a VM on DigitalOcean
# Invoke this twice:
# 1. Invoke with an inventory file containing nothing but 'localhost'
# 2. Invoke with digital_ocean.py inventory plugin as the inventory
# ansible-playbook -i localhost.inv equestria.yml && ansible-playbook -i digital_ocean.py equestria.yml
# Ansible 1.4 (github devel) required for unique_name option
- hosts: localhost
connection: local
sudo: no
gather_facts: no
tasks:
- name: Add SSH key to DigitalOcean account
digital_ocean: >
state=present
command=ssh
name=laptop_ssh_key
ssh_pub_key='{{ lookup('file', '/home/blocke/.ssh/id_rsa.pub') }}'
client_id={{ lookup('file', '/home/blocke/.do-client_id') }}
api_key={{ lookup('file', '/home/blocke/.do-api_key') }}
register: do_ssh_key
# Ubuntu_13.04_x64 512MB VM in New_York2
- name: Create DO VM for Equestria
digital_ocean: >
state=present
command=droplet
name=equestria
region_id=4
image_id=350076
size_id=66
wait=yes
unique_name=yes
ssh_key_ids={{ do_ssh_key.ssh_key.id }}
client_id={{ lookup('file', '/home/blocke/.do-client_id') }}
api_key={{ lookup('file', '/home/blocke/.do-api_key') }}
- hosts: equestria
user: root
tasks:
- name: Install packages
apt: name=nginx state=present
- name: start nginx
service: name=nginx state=started enabled=yes
@connor-t
Copy link

connor-t commented Oct 9, 2013

what does 'register: do_ssh_key' actually do and where does it come from?
I just get the error;

fatal: [localhost] => One or more undefined variables: 'do_ssh_key' is undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment