File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -222,12 +222,17 @@ def v2_playbook_on_play_start(self, play):
222222 api_key , url = self ._load_conf (os .path .join (os .path .dirname (__file__ ), "datadog_callback.yml" ))
223223 # If there is no api key defined in config file, try to get it from hostvars
224224 if api_key == '' :
225+ hostvars = self .play .get_variable_manager ()._hostvars
225226
226- try :
227- api_key = self .play .get_variable_manager ()._hostvars ['localhost' ]['datadog_api_key' ]
228- except Exception , e :
229- print '{0} is not set neither in the config file nor hostvars. Disabling Datadog callback plugin' .format (e )
227+ if not hostvars :
228+ print "No api_key found in the config file and hostvars aren't set: disabling Datadog callback plugin"
230229 self .disabled = True
230+ else :
231+ try :
232+ api_key = hostvars ['localhost' ]['datadog_api_key' ]
233+ except Exception , e :
234+ print '{0} is not set neither in the config file nor hostvars: disabling Datadog callback plugin' .format (e )
235+ self .disabled = True
231236
232237 # Set up API client and send a start event
233238 if not self .disabled :
You can’t perform that action at this time.
0 commit comments