W3cubDocs

/Ansible

community.digitalocean.digital_ocean_droplet – Create and delete a DigitalOcean droplet

Note

This plugin is part of the community.digitalocean collection (version 1.11.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.digitalocean.

To use it in a playbook, specify: community.digitalocean.digital_ocean_droplet.

Synopsis

  • Create and delete a droplet in DigitalOcean and optionally wait for it to be active.

Parameters

Parameter Choices/Defaults Comments
backups
boolean
    Choices:
  • no
  • yes
indicates whether automated backups should be enabled.
id
integer
Numeric, the droplet id you want to operate on.

aliases: droplet_id
image
string
This is the slug of the image you would like the droplet created with.

aliases: image_id
ipv6
boolean
    Choices:
  • no
  • yes
enable IPv6 for your droplet.
monitoring
boolean
    Choices:
  • no
  • yes
indicates whether to install the DigitalOcean agent for monitoring.
name
string
String, this is the name of the droplet - must be formatted by hostname rules.
oauth_token
string / required
DigitalOcean OAuth token. Can be specified in DO_API_KEY, DO_API_TOKEN, or DO_OAUTH_TOKEN environment variables

aliases: API_TOKEN
private_networking
boolean
    Choices:
  • no
  • yes
add an additional, private network interface to droplet for inter-droplet communication.
region
string
This is the slug of the region you would like your server to be created in.

aliases: region_id
resize_disk
boolean
    Choices:
  • no
  • yes
Whether to increase disk size (only consulted if the unique_name is True and size dictates an increase)
size
string
This is the slug of the size you would like the droplet created with.

aliases: size_id
ssh_keys
list / elements=string
array of SSH key Fingerprint that you would like to be added to the server.
state
string
    Choices:
  • present
  • absent
  • active
  • inactive
Indicate desired state of the target.
present will create the named droplet; be mindful of the unique_name parameter.
absent will delete the named droplet, if it exists.
active will create the named droplet (unless it exists) and ensure that it is powered on.
inactive will create the named droplet (unless it exists) and ensure that it is powered off.
tags
list / elements=string
List, A list of tag names as strings to apply to the Droplet after it is created. Tag names can either be existing or new tags.
unique_name
boolean
    Choices:
  • no
  • yes
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
string
opaque blob of data which is made available to the droplet
volumes
list / elements=string
List, A list including the unique string identifier for each Block Storage volume to be attached to the Droplet.
vpc_uuid
string
added in 0.1.0 of community.digitalocean
A string specifying the UUID of the VPC to which the Droplet will be assigned. If excluded, Droplet will be assigned to the account's default VPC for the region.
wait
boolean
    Choices:
  • no
  • yes
Wait for the droplet to be active before returning. If wait is "no" an ip_address may not be returned.
wait_timeout
integer
Default:
120
How long before wait gives up, in seconds, when creating a droplet.

Examples

- name: Create a new droplet
  community.digitalocean.digital_ocean_droplet:
    state: present
    name: mydroplet
    oauth_token: XXX
    size: 2gb
    region: sfo1
    image: ubuntu-16-04-x64
    wait_timeout: 500
    ssh_keys: [ .... ]
  register: my_droplet

- debug:
    msg: "ID is {{ my_droplet.data.droplet.id }}, IP is {{ my_droplet.data.ip_address }}"

- name: Ensure a droplet is present
  community.digitalocean.digital_ocean_droplet:
    state: present
    id: 123
    name: mydroplet
    oauth_token: XXX
    size: 2gb
    region: sfo1
    image: ubuntu-16-04-x64
    wait_timeout: 500

- name: Ensure a droplet is present with SSH keys installed
  community.digitalocean.digital_ocean_droplet:
    state: present
    id: 123
    name: mydroplet
    oauth_token: XXX
    size: 2gb
    region: sfo1
    ssh_keys: ['1534404', '1784768']
    image: ubuntu-16-04-x64
    wait_timeout: 500

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
data
dictionary
changed
a DigitalOcean Droplet

Sample:
{'droplet': {'backup_ids': [], 'created_at': '2014-11-14T16:36:31Z', 'disk': 20, 'features': ['virtio'], 'id': 3164494, 'image': {}, 'kernel': {'id': 2233, 'name': 'Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic', 'version': '3.13.0-37-generic'}, 'locked': True, 'memory': 512, 'name': 'example.com', 'networks': {}, 'region': {}, 'size': {}, 'size_slug': '512mb', 'snapshot_ids': [], 'status': 'new', 'tags': ['web'], 'vcpus': 1, 'volume_ids': []}, 'ip_address': '104.248.118.172', 'ipv6_address': '2604:a880:400:d1::90a:6001', 'private_ipv4_address': '10.136.122.141'}


Authors

  • Gurchet Rai (@gurch101)

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/digitalocean/digital_ocean_droplet_module.html