Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the foreman callback more defensive #36527

Merged
merged 4 commits into from
Apr 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/ansible/plugins/callback/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ def set_options(self, task_keys=None, var_options=None, direct=None):

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.')
Expand All @@ -116,7 +116,10 @@ def set_options(self, task_keys=None, var_options=None, direct=None):

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"]:
Expand Down Expand Up @@ -157,8 +160,10 @@ def _build_log(self, data):
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': {
Expand Down