11import getpass
2- import os .path
32import logging
3+ import os
44import time
55
66try :
@@ -49,12 +49,15 @@ def _set_logger_level(self, name, level=logging.WARNING):
4949 print e
5050
5151 # Load parameters from conf file
52- def _load_conf (self , file_path ):
53- conf_dict = {}
52+ def _load_conf (self ):
53+ file_path = os . environ . get ( 'ANSIBLE_DATADOG_CALLBACK_CONF_FILE' , os . path . join ( os . path . dirname ( __file__ ), "datadog_callback.yml" ))
5454
55+ conf_dict = {}
5556 if os .path .isfile (file_path ):
5657 with open (file_path , 'r' ) as conf_file :
5758 conf_dict = yaml .load (conf_file )
59+ else :
60+ print "Could not load configuration, invalid file: {}" .format (file_path )
5861
5962 return conf_dict .get ('api_key' , '' ), conf_dict .get ('url' , 'https://app.datadoghq.com' )
6063
@@ -226,7 +229,7 @@ def v2_playbook_on_play_start(self, play):
226229 return
227230
228231 # Read config and hostvars
229- api_key , url = self ._load_conf (os . path . join ( os . path . dirname ( __file__ ), "datadog_callback.yml" ) )
232+ api_key , url = self ._load_conf ()
230233 # If there is no api key defined in config file, try to get it from hostvars
231234 if api_key == '' :
232235 hostvars = self .play .get_variable_manager ()._hostvars
@@ -238,7 +241,7 @@ def v2_playbook_on_play_start(self, play):
238241 try :
239242 api_key = hostvars ['localhost' ]['datadog_api_key' ]
240243 except Exception , e :
241- print '{0} is not set neither in the config file nor hostvars: disabling Datadog callback plugin' .format (e )
244+ print 'No "api_key" found in the config file and {0} is not set in the hostvars: disabling Datadog callback plugin' .format (e )
242245 self .disabled = True
243246
244247 # Set up API client and send a start event
0 commit comments