Skip to content

Commit 9278d26

Browse files
Ivan Dimitrovhush-hush
authored andcommitted
Check if datadog library exists before starting
1 parent a7c4f10 commit 9278d26

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

datadog_callback.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
import os.path
33
import time
44

5-
import datadog
6-
import yaml
5+
try:
6+
import datadog
7+
import yaml
8+
HAS_MODULES = True
9+
except ImportError:
10+
HAS_MODULES = False
11+
712

813
from ansible.plugins.callback import CallbackBase
914
from __main__ import cli
1015

1116

1217
class CallbackModule(CallbackBase):
1318
def __init__(self):
19+
if not HAS_MODULES:
20+
self.disabled = True
21+
print 'Datadog callback disabled.\nMake sure you call all required libraries.'
1422

1523
self._playbook_name = None
1624
self._start_time = time.time()
@@ -197,7 +205,8 @@ def v2_playbook_on_start(self, playbook):
197205
def v2_playbook_on_play_start(self, play):
198206
# On Ansible v2, Ansible doesn't set `self.play` automatically
199207
self.play = play
200-
self.disabled = False
208+
if self.disabled:
209+
return
201210

202211
# Read config and hostvars
203212
api_key, url = self._load_conf(os.path.join(os.path.dirname(__file__), "datadog_callback.yml"))

0 commit comments

Comments
 (0)