diff --git a/lib/ansible/modules/cloud/hcloud/hcloud_server.py b/lib/ansible/modules/cloud/hcloud/hcloud_server.py index 2c11838836..7df0ddebbd 100644 --- a/lib/ansible/modules/cloud/hcloud/hcloud_server.py +++ b/lib/ansible/modules/cloud/hcloud/hcloud_server.py @@ -234,10 +234,14 @@ class AnsibleHcloudServer(Hcloud): "server_type": self.client.server_types.get_by_name( self.module.params.get("server_type") ), - "image": self.client.images.get_by_name(self.module.params.get("image")), "user_data": self.module.params.get("user_data"), "labels": self.module.params.get("labels"), } + if self.client.images.get_by_name(self.module.params.get("image")) is not None: + # When image name is not available look for id instead + params["image"] = self.client.images.get_by_name(self.module.params.get("image")) + else: + params["image"] = self.client.images.get_by_id(self.module.params.get("image")) if self.module.params.get("ssh_keys") is not None: params["ssh_keys"] = [ @@ -266,7 +270,7 @@ class AnsibleHcloudServer(Hcloud): if not self.module.check_mode: resp = self.client.servers.create(**params) self.result["root_password"] = resp.root_password - resp.action.wait_until_finished() + resp.action.wait_until_finished(max_retries=1000) [action.wait_until_finished() for action in resp.next_actions] self._mark_as_changed() self._get_server()