ansible-collections / hetzner.hcloud

A collection to manage resources on Hetzner Cloud
https://galaxy.ansible.com/ui/repo/published/hetzner/hcloud
GNU General Public License v3.0
108 stars 38 forks source link

Inventory load fails with server recreated from snapshot #22

Closed dasavick closed 4 years ago

dasavick commented 4 years ago
SUMMARY

Plugin fails to read inventory with vm created from image. Most likely due to the fact that source snapshot was deleted.

ISSUE TYPE
COMPONENT NAME

hcloud

ANSIBLE VERSION
ansible 2.9.11
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.local/lib/python3.8/site-packages/ansible
  executable location = /home/user/.local/bin/ansible
  python version = 3.8.2 (default, Jul 16 2020, 14:00:26) [GCC 9.3.0]
CONFIGURATION

No changes.

OS / ENVIRONMENT

N/A

STEPS TO REPRODUCE
EXPECTED RESULTS

Ansible loads inventory.

ACTUAL RESULTS

The image propery is None for that specific server and causes load fail.

[WARNING]:  * Failed to parse /some/path/hcloud.yml with hcloud plugin: 'NoneType' object has no attribute 'name'
  File "/home/user/.local/lib/python3.8/site-packages/ansible/inventory/manager.py", line 280, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/user/.local/lib/python3.8/site-packages/ansible/plugins/inventory/hcloud.py", line 205, in parse
    self._set_server_attributes(server)
  File "/home/user/.local/lib/python3.8/site-packages/ansible/plugins/inventory/hcloud.py", line 171, in _set_server_attributes
    self.inventory.set_variable(server.name, "server_type", to_native(server.image.name))
dasavick commented 4 years ago

I investigated further and I'm not really sure why this module uses image property to read server_type. Correct property from the API seems to be server_type.name. While image property returned by API is null for that problematic VM, this whole issue looks like it was caused by some mistake:

Current readouts of server_type:

debian-10
debian-10
debian-10
debian-10
debian-10
debian-10

Image section would fail too:

self.inventory.set_variable(server.name, "image_id", to_native(server.image.id))
self.inventory.set_variable(server.name, "image_name", to_native(server.image.name))
self.inventory.set_variable(server.name, "image_os_flavor", to_native(server.image.os_flavor))

At the end I think image property handling is our primary issue while server_type is unrelated mistake. Current API schema shows that image property is nullable so it is probably an issue with the module itself: image

LKaemmerling commented 4 years ago

Please use the collection v0.1.0 (or better: v0.2.0). There it is fixed.

dasavick commented 4 years ago

Thanks, it works. But I still wonder why there is no fallback to server_type.name in case image is not present? Or rather why image name is used instead of server_type.

https://github.com/ansible-collections/hetzner.hcloud/blob/master/plugins/inventory/hcloud.py#L204-L207