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:
parent
b52a6010b6
commit
72fe304b8f
2 changed files with 10 additions and 1 deletions
2
changelogs/fragments/372-gcp_storage_file-gracefully.yml
Normal file
2
changelogs/fragments/372-gcp_storage_file-gracefully.yml
Normal 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."
|
|
@ -48,7 +48,12 @@ import requests
|
|||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.display import Display
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue