From d303c0706c69831f4e5233a5c9d43b8f2db6e5ac Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 12 Apr 2018 15:58:57 +0200 Subject: [PATCH] Make the foreman callback more defensive (#36527) * Foreman: Make the foreman callback more defensive This ensures the ssl_verify attribute is always set. It also handles None in _disable_plugin. * Foreman: Handle ints in verify_certs The default value for verify_certs is 1 which is an int. That has no lower() function. By casting it to a str we can handle it later in _ssl_verify(). * Foreman: Clean up coding style * Foreman: Use get_option in favor of _plugin_options --- lib/ansible/plugins/callback/foreman.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/ansible/plugins/callback/foreman.py b/lib/ansible/plugins/callback/foreman.py index 54559f9244d..f51e9cab52a 100644 --- a/lib/ansible/plugins/callback/foreman.py +++ b/lib/ansible/plugins/callback/foreman.py @@ -94,15 +94,15 @@ class CallbackModule(CallbackBase): super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct) - self.FOREMAN_URL = self._plugin_options['url'] - self.FOREMAN_SSL_CERT = (self._plugin_options['ssl_cert'], self._plugin_options['ssl_key']) - self.FOREMAN_SSL_VERIFY = self._plugin_options['verify_certs'] + self.FOREMAN_URL = self.get_option('url') + self.FOREMAN_SSL_CERT = (self.get_option['ssl_cert'], self.get_option['ssl_key']) + self.FOREMAN_SSL_VERIFY = str(self.get_option['verify_certs']) + + self.ssl_verify = self._ssl_verify() if HAS_REQUESTS: requests_major = int(requests.__version__.split('.')[0]) - if requests_major >= 2: - self.ssl_verify = self._ssl_verify() - else: + if requests_major < 2: self._disable_plugin('The `requests` python module is too old.') else: self._disable_plugin('The `requests` python module is not installed.') @@ -116,7 +116,10 @@ class CallbackModule(CallbackBase): def _disable_plugin(self, msg): self.disabled = True - self._display.warning(msg + ' Disabling the Foreman callback plugin.') + if msg: + self._display.warning(msg + ' Disabling the Foreman callback plugin.') + else: + self._display.warning('Disabling the Foreman callback plugin.') def _ssl_verify(self): if self.FOREMAN_SSL_VERIFY.lower() in ["1", "true", "on"]: @@ -157,8 +160,10 @@ class CallbackModule(CallbackBase): source, msg = entry if 'failed' in msg: level = 'err' + elif 'changed' in msg and msg['changed']: + level = 'notice' else: - level = 'notice' if 'changed' in msg and msg['changed'] else 'info' + level = 'info' logs.append({ "log": { 'sources': {