Deprecated

Removed in 2.0.0

i

Reason:Updated module to remove external dependency with increased functionality. | Alternative:Use M(digital_ocean_droplet) instead.

community.general.digital_ocean (0.2.1) — module

Create/delete a droplet/SSH_key in DigitalOcean

Authors: Vincent Viallet (@zbal)

Install collection

Install with ansible-galaxy collection install community.general:==0.2.1


Add to requirements.yml

  collections:
    - name: community.general
      version: 0.2.1

Description

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


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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

- name: Ensure a SSH key is present
  digital_ocean:
    state: present
    command: ssh
    name: my_ssh_key
    ssh_pub_key: 'ssh-rsa AAAA...'
    api_token: XXX
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Will return the droplet details including the droplet id (used for idempotence)
- name: Create a new Droplet
  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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    msg: "ID is {{ my_droplet.droplet.id }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    msg: "IP is {{ my_droplet.droplet.ip_address }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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.

- name: Ensure a droplet is present
  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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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.

- name: Create a droplet with ssh key
  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

Inputs

    
id:
    aliases:
    - droplet_id
    description:
    - Numeric, the droplet id you want to operate on.

ipv6:
    default: 'no'
    description:
    - Optional, Boolean, enable IPv6 for your droplet.
    type: bool

name:
    description:
    - String, this is the name of the droplet - must be formatted by hostname rules, or
      the name of a SSH key.

wait:
    default: 'yes'
    description:
    - Wait for the droplet to be in state 'running' before returning.  If wait is "no"
      an ip_address may not be returned.
    type: bool

state:
    choices:
    - present
    - active
    - absent
    - deleted
    default: present
    description:
    - Indicate desired state of the target.

virtio:
    default: 'yes'
    description:
    - Bool, turn on virtio driver in droplet for improved network and storage I/O.
    type: bool

command:
    choices:
    - droplet
    - ssh
    default: droplet
    description:
    - Which target you want to operate on.

size_id:
    description:
    - This is the slug of the size you would like the droplet created with.

image_id:
    description:
    - This is the slug of the image you would like the droplet created with.

api_token:
    description:
    - DigitalOcean api token.

region_id:
    description:
    - This is the slug of the region you would like your server to be created in.

user_data:
    description:
    - opaque blob of data which is made available to the droplet

ssh_key_ids:
    description:
    - Optional, array of SSH key (numeric) ID that you would like to be added to the server.

ssh_pub_key:
    description:
    - The public SSH key you want to add to your account.

unique_name:
    default: 'no'
    description:
    - 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.
    type: bool

wait_timeout:
    default: 300
    description:
    - How long before wait gives up, in seconds.

backups_enabled:
    default: 'no'
    description:
    - Optional, Boolean, enables backups for your droplet.
    type: bool

private_networking:
    default: 'no'
    description:
    - Bool, add an additional, private network interface to droplet for inter-droplet
      communication.
    type: bool