Documentation

digital_ocean - Create/delete a droplet/SSH_key in DigitalOcean

New in version 1.3.

Synopsis

  • Create/delete a droplet in DigitalOcean and optionally wait for it to be ‘running’, or deploy an SSH key.

Options

parameter required default choices comments
api_token
(added in 1.9.5)
no
DigitalOcean api token.
backups_enabled
(added in 1.6)
no no
  • yes
  • no
Optional, Boolean, enables backups for your droplet.
command
no droplet
  • droplet
  • ssh
Which target you want to operate on.
id
no
Numeric, the droplet id you want to operate on.
image_id
no
This is the slug of the image you would like the droplet created with.
ipv6
(added in 2.2)
no no
  • yes
  • no
Optional, Boolean, enable IPv6 for your droplet.
name
no
String, this is the name of the droplet - must be formatted by hostname rules, or the name of a SSH key.
private_networking
(added in 1.4)
no no
  • yes
  • no
Bool, add an additional, private network interface to droplet for inter-droplet communication.
region_id
no
This is the slug of the region you would like your server to be created in.
size_id
no
This is the slug of the size you would like the droplet created with.
ssh_key_ids
no
Optional, array of SSH key (numeric) ID that you would like to be added to the server.
ssh_pub_key
no
The public SSH key you want to add to your account.
state
no present
  • present
  • active
  • absent
  • deleted
Indicate desired state of the target.
unique_name
(added in 1.4)
no no
  • yes
  • no
Bool, require unique hostnames. By default, DigitalOcean allows multiple hosts with the same name. Setting this to "yes" allows only one host per name. Useful for idempotence.
user_data
(added in 2.0)
no None
opaque blob of data which is made available to the droplet
virtio
(added in 1.4)
no yes
  • yes
  • no
Bool, turn on virtio driver in droplet for improved network and storage I/O.
wait
no yes
  • yes
  • no
Wait for the droplet to be in state 'running' before returning. If wait is "no" an ip_address may not be returned.
wait_timeout
no 300
How long before wait gives up, in seconds.

Examples

# Ensure a SSH key is present
# If a key matches this name, will return the ssh key id and changed = False
# If no existing key matches this name, a new key is created, the ssh key id is returned and changed = False

- digital_ocean:
    state: present
    command: ssh
    name: my_ssh_key
    ssh_pub_key: 'ssh-rsa AAAA...'
    api_token: XXX

# Create a new Droplet
# Will return the droplet details including the droplet id (used for idempotence)

- digital_ocean:
    state: present
    command: droplet
    name: mydroplet
    api_token: XXX
    size_id: 2gb
    region_id: ams2
    image_id: fedora-19-x64
    wait_timeout: 500
  register: my_droplet

- debug:
    msg: "ID is {{ my_droplet.droplet.id }}"

- debug:
    msg: "IP is {{ my_droplet.droplet.ip_address }}"

# Ensure a droplet is present
# If droplet id already exist, will return the droplet details and changed = False
# If no droplet matches the id, a new droplet will be created and the droplet details (including the new id) are returned, changed = True.

- digital_ocean:
    state: present
    command: droplet
    id: 123
    name: mydroplet
    api_token: XXX
    size_id: 2gb
    region_id: ams2
    image_id: fedora-19-x64
    wait_timeout: 500

# Create a droplet with ssh key
# The ssh key id can be passed as argument at the creation of a droplet (see ssh_key_ids).
# Several keys can be added to ssh_key_ids as id1,id2,id3
# The keys are used to connect as root to the droplet.

- digital_ocean:
    state: present
    ssh_key_ids: 123,456
    name: mydroplet
    api_token: XXX
    size_id: 2gb
    region_id: ams2
    image_id: fedora-19-x64

Notes

Note

  • Two environment variables can be used, DO_API_KEY and DO_API_TOKEN. They both refer to the v2 token.
  • As of Ansible 1.9.5 and 2.0, Version 2 of the DigitalOcean API is used, this removes client_id and api_key options in favor of api_token.
  • If you are running Ansible 1.9.4 or earlier you might not be able to use the included version of this module as the API version used has been retired. Upgrade Ansible or, if unable to, try downloading the latest version of this module from github and putting it into a ‘library’ directory.

Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Support

This module is community maintained without core committer oversight.

For more information on what this means please read Module Support

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Helping Testing PRs and Developing Modules.