community.digitalocean.digital_ocean_droplet module – Create and delete a DigitalOcean droplet
Note
This module is part of the community.digitalocean collection (version 1.23.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 |
Comments |
---|---|
Indicates whether automated backups should be enabled. Choices:
|
|
DigitalOcean API base url. Default: |
|
Array of firewall names to apply to the Droplet. Omitting a firewall name that is currently applied to a droplet will remove it. |
|
The Droplet ID you want to operate on. |
|
This is the slug of the image you would like the Droplet created with. |
|
Enable IPv6 for the Droplet. Choices:
|
|
Indicates whether to install the DigitalOcean agent for monitoring. Choices:
|
|
This is the name of the Droplet. Must be formatted by hostname rules. |
|
DigitalOcean OAuth token. There are several other environment variables which can be used to provide this value. i.e., - ‘DO_API_TOKEN’, ‘DO_API_KEY’, ‘DO_OAUTH_TOKEN’ and ‘OAUTH_TOKEN’ |
|
Add an additional, private network interface to the Droplet (for inter-Droplet communication). Choices:
|
|
Project to assign the resource to (project name, not UUID). Defaults to the default project of the account (empty string). Currently only supported when creating. Default: |
|
This is the slug of the region you would like your Droplet to be created in. |
|
Whether to increase disk size on resize. Only consulted if the Droplet Choices:
|
|
This is the slug of the size you would like the Droplet created with. Please see https://slugs.do-api.dev/ for current slugs. |
|
How long to Default is 10 seconds; this should be less than Default: |
|
Array of SSH key fingerprints that you would like to be added to the Droplet. |
|
Indicate desired state of the target.
Choices:
|
|
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. |
|
The timeout in seconds used for polling DigitalOcean’s API. Default: |
|
Require unique hostnames. By default, DigitalOcean allows multiple hosts with the same name. Setting this to Useful for idempotence. Choices:
|
|
Opaque blob of data which is made available to the Droplet. |
|
If set to This should only set to Choices:
|
|
A list including the unique string identifier for each Block Storage volume to be attached to the Droplet. |
|
A string specifying the UUID of the VPC to which the Droplet will be assigned. If excluded, the Droplet will be assigned to the account’s default VPC for the region. |
|
Wait for the Droplet to be active before returning. If wait is Choices:
|
|
How long before Default: |
Examples
- name: Create a new Droplet
community.digitalocean.digital_ocean_droplet:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
name: mydroplet
size: s-1vcpu-1gb
region: sfo3
image: ubuntu-20-04-x64
wait_timeout: 500
ssh_keys: [ .... ]
register: my_droplet
- name: Show Droplet info
ansible.builtin.debug:
msg: |
Droplet ID is {{ my_droplet.data.droplet.id }}
First Public IPv4 is {{ (my_droplet.data.droplet.networks.v4 | selectattr('type', 'equalto', 'public')).0.ip_address | default('<none>', true) }}
First Private IPv4 is {{ (my_droplet.data.droplet.networks.v4 | selectattr('type', 'equalto', 'private')).0.ip_address | default('<none>', true) }}
- name: Create a new Droplet (and assign to Project "test")
community.digitalocean.digital_ocean_droplet:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
name: mydroplet
size: s-1vcpu-1gb
region: sfo3
image: ubuntu-20-04-x64
wait_timeout: 500
ssh_keys: [ .... ]
project: test
register: my_droplet
- name: Ensure a Droplet is present
community.digitalocean.digital_ocean_droplet:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
id: 123
name: mydroplet
size: s-1vcpu-1gb
region: sfo3
image: ubuntu-20-04-x64
wait_timeout: 500
- name: Ensure a Droplet is present and has firewall rules applied
community.digitalocean.digital_ocean_droplet:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
id: 123
name: mydroplet
size: s-1vcpu-1gb
region: sfo3
image: ubuntu-20-04-x64
firewall: ['myfirewall', 'anotherfirewall']
wait_timeout: 500
- name: Ensure a Droplet is present with SSH keys installed
community.digitalocean.digital_ocean_droplet:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
id: 123
name: mydroplet
size: s-1vcpu-1gb
region: sfo3
ssh_keys: ['1534404', '1784768']
image: ubuntu-20-04-x64
wait_timeout: 500
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Assignment status (ok, not_found, assigned, already_assigned, service_down) Returned: changed Sample: |
|
a DigitalOcean Droplet Returned: changed Sample: |
|
Informational or error message encountered during execution Returned: changed Sample: |
|
Resource assignment involved in project assignment Returned: changed Sample: |