Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
CHANGELOG
=========

# 2.1.0 / 2017-12-26
- [FEATURE] Disable callback if required python packages aren't installed. See [#28][] (thanks to @dobber)

# 2.0.0 / 2017-12-12
- [FEATURE] Add support for getting api_key from hostvars and thus from vault. See [#25][]
- [BREAKING CHANGE] Drop support for ansible <2.0
Expand Down
17 changes: 14 additions & 3 deletions datadog_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
import os.path
import time

import datadog
import yaml
try:
import datadog
import yaml
HAS_MODULES = True
except ImportError:
HAS_MODULES = False


from ansible.plugins.callback import CallbackBase
from __main__ import cli


class CallbackModule(CallbackBase):
def __init__(self):
if not HAS_MODULES:
self.disabled = True
print 'Datadog callback disabled.\nMake sure you call all required libraries: "datadog" and "yaml".'
else:
self.disabled = False

self._playbook_name = None
self._start_time = time.time()
Expand Down Expand Up @@ -197,7 +207,8 @@ def v2_playbook_on_start(self, playbook):
def v2_playbook_on_play_start(self, play):
# On Ansible v2, Ansible doesn't set `self.play` automatically
self.play = play
self.disabled = False
if self.disabled:
return

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