droplet_action_power

Synopsis

  • Set power states of a Droplet.

  • State power_on powers on a Droplet.

  • State power_off is a hard shutdown and should only be used if the shutdown action is not successful. It is similar to cutting the power on a server and could lead to complications.

  • State shutdown is an attempt to shutdown the Droplet in a graceful way, similar to using the shutdown command from the console. Since a shutdown command can fail, this action guarantees that the command is issued, not that it succeeds. The preferred way to turn off a Droplet is to attempt a shutdown, with a reasonable timeout, followed by a power_off state to ensure the Droplet is off.

  • View the API documentation at https://docs.digitalocean.com/reference/api/api-reference/#tag/Droplet-Actions.

Requirements

  • pydo >= 0.1.3
  • azure-core >= 1.26.1

Parameters

Parameter Choices Default Comments
client_override_options
(dict)
Client override options (developer use). For example, can be used to override the DigitalOcean API endpoint for an internal test suite. If provided, these options will knock out existing options.
droplet_id
(int)
A unique identifier for a Droplet instance. If provided, name and region are ignored.
force_power_off
(bool)
False Force power off if shutdown fails.
module_override_options
(dict)
Module override options (developer use). Can be used to override module options to support experimental or future options. If provided, these options will knock out existing options.
name
(str)
The name of the Droplet to act on. If provided, must be unique and given with region.
region
(str)
The name of the Droplet to act on. Required with name.
state
(str)
  • power_off
  • power_on
  • shutdown
power_on The power state transition.
timeout
(int)
300 Polling timeout in seconds.
token
(str)
DigitalOcean API token. There are several environment variables which can be used to provide this value. DIGITALOCEAN_ACCESS_TOKEN, DIGITALOCEAN_TOKEN, DO_API_TOKEN, DO_API_KEY, DO_OAUTH_TOKEN and OAUTH_TOKEN

Examples

- name: Power off a Droplet
  digitalocean.cloud.droplet_action_power:
    token: "{{ token }}"
    state: power_off
    id: 1122334455

- name: Power on a Droplet
  digitalocean.cloud.droplet_action_power:
    token: "{{ token }}"
    state: power_on
    id: 1122334455

- name: Shut down a Droplet
  digitalocean.cloud.droplet_action_power:
    token: "{{ token }}"
    state: shutdown
    id: 1122334455

- name: Shut down a Droplet (force if unsuccessful)
  digitalocean.cloud.droplet_action_power:
    token: "{{ token }}"
    state: shutdown
    force_power_off: true
    id: 1122334455

Return Values

Key Returned Description
action
(dict)
always DigitalOcean action information.

Sample:

{
  "completed_at": null,
  "id": 1882339039,
  "region": {
    "available": true,
    "features": [
      "backups",
      "ipv6",
      "metadata",
      "install_agent",
      "storage",
      "image_transfer"
    ],
    "name": "New York 3",
    "sizes": [
      "s-1vcpu-1gb",
      "s-1vcpu-1gb-amd",
      "s-1vcpu-1gb-intel",
      "and many more"
    ],
    "slug": "nyc3"
  },
  "region_slug": "nyc3",
  "resource_id": 336851565,
  "resource_type": "droplet",
  "started_at": "2023-09-03T12:59:10Z",
  "status": "in-progress",
  "type": "power_on"
}
error
(dict)
failure DigitalOcean API error.

Sample:

{
  "Message": "Informational error message.",
  "Reason": "Unauthorized",
  "Status Code": 401
}
msg
(str)
always DigitalOcean action information.

Sample:

[
  "No Droplet with ID 336851565",
  "No Droplet with name test-droplet-1 in nyc3",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027power_off\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027power_off\u0027 and it has not completed, status is \u0027in-progress\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027power_off\u0027 and it has not completed, status is \u0027errored\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 would be sent action \u0027power_off\u0027, it is \u0027off\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 would not be sent action \u0027power_off\u0027, it is \u0027active\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 not sent action \u0027power_off\u0027, it is \u0027off\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027power_on\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027power_on\u0027 and it has not completed, status is \u0027in-progress\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027power_on\u0027 and it has not completed, status is \u0027errored\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 would be sent action \u0027power_on\u0027, it is \u0027active\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 would not be sent action \u0027power_on\u0027, it is \u0027off\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 not sent action \u0027power_on\u0027, it is \u0027active\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027shutdown\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027shutdown\u0027 and it has not completed, status is \u0027in-progress\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 sent action \u0027shutdown\u0027 and it has not completed, status is \u0027errored\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 would be sent action \u0027shutdown\u0027, it is \u0027active\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 would not be sent action \u0027shutdown\u0027, it is \u0027off\u0027",
  "Droplet test-droplet-1 (336851565) in nyc3 not sent action \u0027shutdown\u0027, it is \u0027off\u0027"
]