ansible-collections / community.digitalocean

This Ansible collection contains modules for assisting in the automation of the DigitalOcean cloud.
https://galaxy.ansible.com/community/digitalocean/
GNU General Public License v3.0
141 stars 57 forks source link

`digital_ocean_droplet` action raises python error when api returns 500 #192

Open y8 opened 2 years ago

y8 commented 2 years ago
SUMMARY

When API returns 500 status, digital_ocean_droplet with action: create raises python error.

ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
ansible [core 2.11.6]
  config file =<snip>/ansible.cfg
  configured module search path = ['/Users/<snip>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/4.8.0/libexec/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/y13/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.10.0 (default, Oct 12 2021, 22:37:59) [Clang 13.0.0 (clang-1300.0.29.3)]
  jinja version = 3.0.2
  libyaml = True
COLLECTION VERSION
# /Users/<snip>/.ansible/collections/ansible_collections
Collection             Version
---------------------- -------
community.digitalocean 1.12.0

# /opt/homebrew/Cellar/ansible/4.8.0/libexec/lib/python3.10/site-packages/ansible_collections
Collection             Version
---------------------- -------
community.digitalocean 1.11.0
CONFIGURATION
DEFAULT_STDOUT_CALLBACK(<snip>/ansible.cfg) = debug
DEFAULT_VAULT_PASSWORD_FILE(<snip>/ansible.cfg) = <snip>
OS / ENVIRONMENT

MacBookAir10,1 (M1, aarch64) Darwin 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101 arm64

STEPS TO REPRODUCE

You can't reproduce actual API failure, but it can be reproduced by mocking response with code 500 and body:

{ "id": "unprocessable_entity", "message": "Internal Server Error"}
- name: Create droplet
  delegate_to: localhost
  community.digitalocean.digital_ocean_droplet:
    state: active
    name: test-name
    unique_name: yes
    private_networking: yes
    monitoring: yes
    size: "s-1vcpu-2gb-amd"
    image: "docker-20-04"
    region: "fra1"
    wait: yes
    wait_timeout: 500
  register: droplet_info

Raised 'NoneType' object has no attribute 'get' Stacktrace points to: https://github.com/ansible-collections/community.digitalocean/blob/3e81f0c9ac16cd34aff609577b359deb0028e7a3/plugins/modules/digital_ocean_droplet.py#L708

I suppose status_code should be checked before droplet and droplet_id are fetched from response

Thanks!

djholms commented 2 years ago

I have the same issue. System: Debian 11

  config file = /home/user/workspace/debug_DigitalOcean_Droplet_Management/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]

Collection

# /home/user/.ansible/collections/ansible_collections
Collection             Version
---------------------- -------
community.digitalocean 1.12.0 

Manifest

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

Issue is the same as in topic Thanks for support