community.digitalocean.digital_ocean_droplet (1.26.0) — module

Create and delete a DigitalOcean droplet

Authors: Gurchet Rai (@gurch101), Mark Mercado (@mamercad)

Install collection

Install with ansible-galaxy collection install community.digitalocean:==1.26.0


Add to requirements.yml

  collections:
    - name: community.digitalocean
      version: 1.26.0

Description

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

Usage examples

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

Inputs

    
id:
    aliases:
    - droplet_id
    description:
    - The Droplet ID you want to operate on.
    type: int

ipv6:
    default: false
    description:
    - Enable IPv6 for the Droplet.
    required: false
    type: bool

name:
    description:
    - This is the name of the Droplet.
    - Must be formatted by hostname rules.
    type: str

size:
    aliases:
    - size_id
    description:
    - This is the slug of the size you would like the Droplet created with.
    - Please see U(https://slugs.do-api.dev/) for current slugs.
    type: str

tags:
    description:
    - 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.
    elements: str
    required: false
    type: list

wait:
    default: true
    description:
    - Wait for the Droplet to be active before returning.
    - If wait is C(false) an IP address may not be returned.
    required: false
    type: bool

image:
    aliases:
    - image_id
    description:
    - This is the slug of the image you would like the Droplet created with.
    type: str

state:
    choices:
    - present
    - absent
    - active
    - inactive
    default: present
    description:
    - Indicate desired state of the target.
    - C(present) will create the named droplet; be mindful of the C(unique_name) parameter.
    - C(absent) will delete the named droplet, if it exists.
    - C(active) will create the named droplet (unless it exists) and ensure that it is
      powered on.
    - C(inactive) will create the named droplet (unless it exists) and ensure that it
      is powered off.
    type: str

region:
    aliases:
    - region_id
    description:
    - This is the slug of the region you would like your Droplet to be created in.
    type: str

backups:
    default: false
    description:
    - Indicates whether automated backups should be enabled.
    required: false
    type: bool

baseurl:
    default: https://api.digitalocean.com/v2
    description:
    - DigitalOcean API base url.
    type: str

timeout:
    default: 30
    description:
    - The timeout in seconds used for polling DigitalOcean's API.
    type: int

volumes:
    description:
    - A list including the unique string identifier for each Block Storage volume to be
      attached to the Droplet.
    elements: str
    required: false
    type: list

firewall:
    description:
    - Array of firewall names to apply to the Droplet.
    - Omitting a firewall name that is currently applied to a droplet will remove it.
    elements: str
    required: false
    type: list

ssh_keys:
    description:
    - Array of SSH key fingerprints that you would like to be added to the Droplet.
    elements: str
    required: false
    type: list

vpc_uuid:
    description:
    - 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.
    type: str
    version_added: 0.1.0
    version_added_collection: community.digitalocean

user_data:
    description:
    - Opaque blob of data which is made available to the Droplet.
    required: false
    type: str

monitoring:
    default: false
    description:
    - Indicates whether to install the DigitalOcean agent for monitoring.
    required: false
    type: bool

oauth_token:
    aliases:
    - api_token
    description:
    - DigitalOcean OAuth token.
    - There are several other environment variables which can be used to provide this
      value.
    - i.e., - C(DO_API_TOKEN), C(DO_API_KEY), C(DO_OAUTH_TOKEN) and C(OAUTH_TOKEN).
    type: str

resize_disk:
    default: false
    description:
    - Whether to increase disk size on resize.
    - Only consulted if the C(unique_name) is C(true).
    - Droplet C(size) must dictate an increase.
    required: false
    type: bool

unique_name:
    default: false
    description:
    - Require unique hostnames.
    - By default, DigitalOcean allows multiple hosts with the same name.
    - Setting this to C(true) allows only one host per name.
    - Useful for idempotence.
    type: bool

project_name:
    aliases:
    - project
    default: ''
    description:
    - 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.
    required: false
    type: str

wait_timeout:
    default: 120
    description:
    - How long before C(wait) gives up, in seconds, when creating a Droplet.
    type: int

sleep_interval:
    default: 10
    description:
    - How long to C(sleep) in between action and status checks.
    - Default is 10 seconds; this should be less than C(wait_timeout) and nonzero.
    type: int

validate_certs:
    default: true
    description:
    - If set to C(no), the SSL certificates will not be validated.
    - This should only set to C(no) used on personally controlled sites using self-signed
      certificates.
    type: bool

private_networking:
    default: false
    description:
    - Add an additional, private network interface to the Droplet (for inter-Droplet communication).
    type: bool

Outputs

assign_status:
  description: Assignment status (ok, not_found, assigned, already_assigned, service_down)
  returned: changed
  sample: assigned
  type: str
data:
  description: a DigitalOcean Droplet
  returned: changed
  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
  type: dict
msg:
  description: Informational or error message encountered during execution
  returned: changed
  sample: No project named test2 found
  type: str
resources:
  description: Resource assignment involved in project assignment
  returned: changed
  sample:
    assigned_at: '2021-10-25T17:39:38Z'
    links:
      self: https://api.digitalocean.com/v2/droplets/3164494
    status: assigned
    urn: do:droplet:3164494
  type: dict