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

Add support for not sending callback data for certain hosts. #1529

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions plugins/callback/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@
ini:
- section: callback_foreman
key: dir_store
ignore_hosts:
description:
- Any hosts matching the set regex pattern will not be reported to Foreman.
- This can be useful for not reporting "localhost" facts.
env:
- name: FOREMAN_IGNORE_HOSTS
default: ''
ini:
- section: callback_foreman
key: ignore_hosts
disable_callback:
description:
- Toggle to make the callback plugin disable itself even if it is loaded.
Expand All @@ -109,6 +119,7 @@
from datetime import datetime
from collections import defaultdict
import json
import re
import time

try:
Expand Down Expand Up @@ -197,6 +208,8 @@ def set_options(self, task_keys=None, var_options=None, direct=None):
ssl_cert = self.get_option('client_cert')
ssl_key = self.get_option('client_key')
self.dir_store = self.get_option('dir_store')
self.ignore_hosts = self.get_option('ignore_hosts')
self._ignored_hosts_notified = []

if not HAS_REQUESTS:
self._disable_plugin(u'The `requests` python module is not installed')
Expand Down Expand Up @@ -234,6 +247,12 @@ def _ssl_verify(self, option):
return verify

def _send_data(self, data_type, report_type, host, data):
if self.ignore_hosts and re.match(self.ignore_hosts, host):
if not host in self._ignored_hosts_notified:
self._display.warning(u'Not sending callback data for ignored host: {host}'.format(host=to_text(host)))
self._ignored_hosts_notified.append(host)
return

if data_type == 'facts':
url = self.foreman_url + '/api/v2/hosts/facts'
elif data_type == 'report' and report_type == 'foreman':
Expand Down