Skip to content

Commit beb95e7

Browse files
committed
Avoid printing error about the conf file when customer use a vault
1 parent 33270de commit beb95e7

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
CHANGELOG
22
=========
33

4+
# 2.4.1 / 2018-02-07
5+
- [BUGFIX] Avoid printing error about the conf file when using a vault. See [#34][]
6+
47
# 2.4.0 / 2018-02-07
58
- [FEATURE] Add support of python3 (and still fully support python2). See [#33][] (thanks to [@DSpeichert][])
69

datadog_callback.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,14 @@ def _set_logger_level(self, name, level=logging.WARNING):
4949
print(e)
5050

5151
# Load parameters from conf file
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"))
54-
52+
def _load_conf(self, file_path):
5553
conf_dict = {}
5654
if os.path.isfile(file_path):
5755
with open(file_path, 'r') as conf_file:
5856
conf_dict = yaml.load(conf_file)
59-
else:
60-
print("Could not load configuration, invalid file: {}".format(file_path))
6157

6258
return os.environ.get('DATADOG_API_KEY', conf_dict.get('api_key', '')), conf_dict.get('url', 'https://app.datadoghq.com')
6359

64-
6560
# Send event to Datadog
6661
def _send_event(self, title, alert_type=None, text=None, tags=None, host=None, event_type=None, event_object=None):
6762
if tags is None:
@@ -234,19 +229,21 @@ def v2_playbook_on_play_start(self, play):
234229
return
235230

236231
# Read config and hostvars
237-
api_key, url = self._load_conf()
232+
config_path = os.environ.get('ANSIBLE_DATADOG_CALLBACK_CONF_FILE', os.path.join(os.path.dirname(__file__), "datadog_callback.yml"))
233+
api_key, url = self._load_conf(config_path)
234+
238235
# If there is no api key defined in config file, try to get it from hostvars
239236
if api_key == '':
240237
hostvars = self.play.get_variable_manager()._hostvars
241238

242239
if not hostvars:
243-
print("No api_key found in the config file and hostvars aren't set: disabling Datadog callback plugin")
240+
print("No api_key found in the config file ({0}) and hostvars aren't set: disabling Datadog callback plugin".format(config_path))
244241
self.disabled = True
245242
else:
246243
try:
247244
api_key = hostvars['localhost']['datadog_api_key']
248245
except Exception as e:
249-
print('No "api_key" found in the config file and {0} is not set in the hostvars: disabling Datadog callback plugin'.format(e))
246+
print('No "api_key" found in the config file ({0}) and "datadog_api_key" is not set in the hostvars: disabling Datadog callback plugin'.format(config_path))
250247
self.disabled = True
251248

252249
# Set up API client and send a start event

0 commit comments

Comments
 (0)