mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
fix: do not error on location_info invalid id (#292)
* test: fix hcloud_location_info with wrong id test * chore: cleanup hcloud_location_info tests * fix: error on location_info invalid id
This commit is contained in:
parent
dd5ee78386
commit
5c4079e059
5 changed files with 44 additions and 40 deletions
|
|
@ -78,7 +78,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
from ..module_utils.hcloud import AnsibleHCloud
|
||||
from ..module_utils.vendor.hcloud import HCloudException
|
||||
from ..module_utils.vendor.hcloud import APIException, HCloudException
|
||||
|
||||
|
||||
class AnsibleHCloudLocationInfo(AnsibleHCloud):
|
||||
|
|
@ -105,7 +105,12 @@ class AnsibleHCloudLocationInfo(AnsibleHCloud):
|
|||
def get_locations(self):
|
||||
try:
|
||||
if self.module.params.get("id") is not None:
|
||||
self.hcloud_location_info = [self.client.locations.get_by_id(self.module.params.get("id"))]
|
||||
try:
|
||||
self.hcloud_location_info = [self.client.locations.get_by_id(self.module.params.get("id"))]
|
||||
except APIException as exception:
|
||||
self.hcloud_location_info = []
|
||||
if exception.code != "not_found":
|
||||
raise exception
|
||||
elif self.module.params.get("name") is not None:
|
||||
self.hcloud_location_info = [self.client.locations.get_by_name(self.module.params.get("name"))]
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue