1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

gcp_storage_file: error gracefully when google.cloud is not there (#372)

* Error gracefully when google.cloud is not there.

* Add changelog fragment.
This commit is contained in:
Felix Fontein 2020-05-19 23:06:40 +02:00 committed by GitHub
parent b52a6010b6
commit 72fe304b8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "gcp_storage_file lookup - die gracefully when the ``google.cloud`` collection is not installed, or changed in an incompatible way."

View file

@ -48,7 +48,12 @@ import requests
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from ansible.utils.display import Display
from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import navigate_hash, GcpSession
try:
from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import navigate_hash, GcpSession
HAS_GOOGLE_CLOUD_COLLECTION = True
except ImportError:
HAS_GOOGLE_CLOUD_COLLECTION = False
display = Display()
@ -135,4 +140,6 @@ class GcpFileLookup():
class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):
if not HAS_GOOGLE_CLOUD_COLLECTION:
raise AnsibleError("community.general.gcp_storage_files needs a supported version of the google.cloud collection installed")
return GcpFileLookup().run(terms, variables=variables, **kwargs)