From 1702937ab3bb23c6c2716f7dafd8623b12283570 Mon Sep 17 00:00:00 2001
From: Michael Scherer <mscherer@users.noreply.github.com>
Date: Sat, 17 Sep 2016 21:33:46 +0200
Subject: [PATCH] Do not import xenapi without checking, so we can avoid
 (#1953)

backtrace
---
 lib/ansible/modules/extras/cloud/xenserver_facts.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/ansible/modules/extras/cloud/xenserver_facts.py b/lib/ansible/modules/extras/cloud/xenserver_facts.py
index d679afce85..fdefee9f2e 100644
--- a/lib/ansible/modules/extras/cloud/xenserver_facts.py
+++ b/lib/ansible/modules/extras/cloud/xenserver_facts.py
@@ -28,7 +28,13 @@ author:
 '''
 
 import platform
-import XenAPI
+
+HAVE_XENAPI = False
+try:
+    import XenAPI
+    HAVE_XENAPI = True
+except ImportError:
+    pass
 
 EXAMPLES = '''
 - name: Gather facts from xenserver
@@ -158,6 +164,9 @@ def get_srs(session):
 def main():
     module = AnsibleModule({})
 
+    if not HAVE_XENAPI:
+        module.fail_json(changed=False, msg="python xen api required for this module")
+
     obj = XenServerFacts()
     try:
         session = get_xenapi_session()