From fa1d55f6834a2fff32093c9e87436d416a15e147 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Fri, 29 Jul 2016 13:34:09 -0400 Subject: [PATCH] Fix import of gce/gcdns without a libcloud module The module level function defs for gcdns_connect() and gce_connect() provide a default arg for 'provider' that references into the libcloud module. If the libcloud modules were not installed, the gce/gcdns python modules would throw ImportError. Let the provider arg default to None and if not provided, set it to the default libcloud.compute.types.Provider.* value if the modules are installed. --- lib/ansible/module_utils/gcdns.py | 3 ++- lib/ansible/module_utils/gce.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/gcdns.py b/lib/ansible/module_utils/gcdns.py index 7227e9be66f..c4b9cbd9dbe 100644 --- a/lib/ansible/module_utils/gcdns.py +++ b/lib/ansible/module_utils/gcdns.py @@ -40,11 +40,12 @@ except ImportError: USER_AGENT_PRODUCT = "Ansible-gcdns" USER_AGENT_VERSION = "v1" -def gcdns_connect(module, provider=Provider.GOOGLE): +def gcdns_connect(module, provider=None): """Return a GCP connection for Google Cloud DNS.""" if not HAS_LIBCLOUD_BASE: module.fail_json(msg='libcloud must be installed to use this module') + provider = provider or Provider.GOOGLE return gcp_connect(module, provider, get_driver, USER_AGENT_PRODUCT, USER_AGENT_VERSION) def unexpected_error_msg(error): diff --git a/lib/ansible/module_utils/gce.py b/lib/ansible/module_utils/gce.py index 85717bb5c5d..1084b9dccd3 100644 --- a/lib/ansible/module_utils/gce.py +++ b/lib/ansible/module_utils/gce.py @@ -40,10 +40,11 @@ except ImportError: USER_AGENT_PRODUCT = "Ansible-gce" USER_AGENT_VERSION = "v1" -def gce_connect(module, provider=Provider.GCE): +def gce_connect(module, provider=None): """Return a GCP connection for Google Compute Engine.""" if not HAS_LIBCLOUD_BASE: module.fail_json(msg='libcloud must be installed to use this module') + provider = provider or Provider.GCE return gcp_connect(module, provider, get_driver, USER_AGENT_PRODUCT, USER_AGENT_VERSION)