File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 55import os
66import time
77
8+ IMPORT_ERROR = None
89try :
910 import datadog
1011 import yaml
1112 from packaging import version
12- HAS_MODULES = True
13- except ImportError :
14- HAS_MODULES = False
13+ except ImportError as e :
14+ IMPORT_ERROR = str (e )
1515
1616
1717import ansible
1818from ansible .plugins .callback import CallbackBase
1919from __main__ import cli
2020
2121ANSIBLE_ABOVE_28 = False
22- if HAS_MODULES and version .parse (ansible .__version__ ) >= version .parse ('2.8.0' ):
22+ if IMPORT_ERROR is None and version .parse (ansible .__version__ ) >= version .parse ('2.8.0' ):
2323 ANSIBLE_ABOVE_28 = True
2424 from ansible .context import CLIARGS
2525
2626DEFAULT_DD_URL = "https://api.datadoghq.com"
2727
2828class CallbackModule (CallbackBase ):
2929 def __init__ (self ):
30- if not HAS_MODULES :
30+ if IMPORT_ERROR is not None :
3131 self .disabled = True
32- print ('Datadog callback disabled: missing "datadog", "yaml", and/or "packaging" python package.' )
32+ print (
33+ 'Datadog callback disabled because of a dependency problem: {}. '
34+ 'Please install requirements with "pip install -r requirements.txt"'
35+ .format (IMPORT_ERROR )
36+ )
3337 else :
3438 self .disabled = False
3539 # Set logger level - datadog api and urllib3
@@ -39,7 +43,7 @@ def __init__(self):
3943 self ._playbook_name = None
4044 self ._start_time = time .time ()
4145 self ._options = None
42- if HAS_MODULES and cli :
46+ if IMPORT_ERROR is None and cli :
4347 if ANSIBLE_ABOVE_28 :
4448 self ._options = CLIARGS
4549 else :
You can’t perform that action at this time.
0 commit comments