diff --git a/plugins/modules/digital_ocean_droplet.py b/plugins/modules/digital_ocean_droplet.py index 495aca7b..ea915027 100644 --- a/plugins/modules/digital_ocean_droplet.py +++ b/plugins/modules/digital_ocean_droplet.py @@ -621,6 +621,17 @@ def wait_action(self, droplet_id, desired_action_data): json_data = response.json status_code = response.status_code message = json_data.get("message", "no error message") + + # action and other fields may not be available in case of error, check first + # will catch Not Authorized due to restrictive Scopes + if status_code >= 400: + self.module.fail_json( + changed=False, + msg=DODroplet.failure_message["failed_to"].format( + "post", "action", status_code, message + ), + ) + action = json_data.get("action", None) action_id = action.get("id", None) action_status = action.get("status", None) @@ -633,14 +644,6 @@ def wait_action(self, droplet_id, desired_action_data): ), ) - if status_code >= 400: - self.module.fail_json( - changed=False, - msg=DODroplet.failure_message["failed_to"].format( - "post", "action", status_code, message - ), - ) - # Keep checking till it is done or times out self.wait_check_action(droplet_id, action_id) diff --git a/poetry.lock b/poetry.lock index 9bbc0e98..e8a47089 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1027,13 +1027,13 @@ requirements-deprecated-finder = ["pip-api", "pipreqs"] [[package]] name = "jinja2" -version = "3.1.3" +version = "3.1.4" description = "A very fast and expressive template engine." optional = false python-versions = ">=3.7" files = [ - {file = "Jinja2-3.1.3-py3-none-any.whl", hash = "sha256:7d6d50dd97d52cbc355597bd845fabfbac3f551e1f99619e39a35ce8c370b5fa"}, - {file = "Jinja2-3.1.3.tar.gz", hash = "sha256:ac8bd6544d4bb2c9792bf3a159e80bba8fda7f07e81bc3aed565432d5925ba90"}, + {file = "jinja2-3.1.4-py3-none-any.whl", hash = "sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d"}, + {file = "jinja2-3.1.4.tar.gz", hash = "sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369"}, ] [package.dependencies] @@ -1649,13 +1649,13 @@ rpds-py = ">=0.7.0" [[package]] name = "requests" -version = "2.31.0" +version = "2.32.2" description = "Python HTTP for Humans." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, - {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, + {file = "requests-2.32.2-py3-none-any.whl", hash = "sha256:fc06670dd0ed212426dfeb94fc1b983d917c4f9847c863f313c9dfaaffb7c23c"}, + {file = "requests-2.32.2.tar.gz", hash = "sha256:dd951ff5ecf3e3b3aa26b40703ba77495dab41da839ae72ef3c8e5d8e2433289"}, ] [package.dependencies]