Skip to content

Commit d5fb589

Browse files
committed
Update error message when hostvars aren't set
1 parent 47e9d42 commit d5fb589

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

datadog_callback.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)