From 83a769292cbdc0f1f6528c5a2feeb0772d50b495 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 25 Jan 2022 10:33:24 +0100 Subject: [PATCH 01/18] Cleanup for initial collection --- playbooks/ansible-example.yml | 18 -- plugins/checkmk_changes/checkmk_changes.py | 153 ----------- plugins/checkmk_host/checkmk_host.py | 260 ------------------- plugins/checkmk_services/checkmk_services.py | 144 ---------- plugins/modules/checkmk_api.py | 157 ----------- roles/host_agent/defaults/main.yml | 9 - roles/host_agent/files/check_mk.ini | 222 ---------------- roles/host_agent/meta/main.yml | 9 - roles/host_agent/tasks/Debian-tasks.yml | 13 - roles/host_agent/tasks/RedHat-tasks.yml | 14 - roles/host_agent/tasks/Windows-tasks.yml | 30 --- roles/host_agent/tasks/main.yml | 4 - roles/host_agent/vars/cmk_agent_generic.yml | 12 - roles/host_plugins/defaults/main.yml | 78 ------ roles/host_plugins/files/apache_status.cfg | 47 ---- roles/host_plugins/files/ceph.cfg | 2 - roles/host_plugins/files/dnsclient.cfg | 1 - roles/host_plugins/files/jar_signature.cfg | 2 - roles/host_plugins/files/logwatch.cfg | 59 ----- roles/host_plugins/files/mk_oracle_cfg.ps1 | 13 - roles/host_plugins/meta/main.yml | 9 - roles/host_plugins/tasks/Linux-install.yml | 18 -- roles/host_plugins/tasks/Linux-main.yml | 31 --- roles/host_plugins/tasks/Linux-remove.yml | 12 - roles/host_plugins/tasks/Linux-search.yml | 23 -- roles/host_plugins/tasks/Windows-install.yml | 12 - roles/host_plugins/tasks/Windows-main.yml | 32 --- roles/host_plugins/tasks/Windows-remove.yml | 12 - roles/host_plugins/tasks/Windows-search.yml | 23 -- roles/host_plugins/tasks/main.yml | 19 -- roles/host_plugins/vars/Linux-vars.yml | 5 - roles/host_plugins/vars/Windows-vars.yml | 5 - roles/host_registration/defaults/main.yml | 6 - roles/host_registration/handlers/main.yml | 10 - roles/host_registration/meta/main.yml | 9 - roles/host_registration/tasks/main.yml | 22 -- 36 files changed, 1495 deletions(-) delete mode 100644 playbooks/ansible-example.yml delete mode 100644 plugins/checkmk_changes/checkmk_changes.py delete mode 100644 plugins/checkmk_host/checkmk_host.py delete mode 100644 plugins/checkmk_services/checkmk_services.py delete mode 100644 plugins/modules/checkmk_api.py delete mode 100644 roles/host_agent/defaults/main.yml delete mode 100644 roles/host_agent/files/check_mk.ini delete mode 100644 roles/host_agent/meta/main.yml delete mode 100644 roles/host_agent/tasks/Debian-tasks.yml delete mode 100644 roles/host_agent/tasks/RedHat-tasks.yml delete mode 100644 roles/host_agent/tasks/Windows-tasks.yml delete mode 100644 roles/host_agent/tasks/main.yml delete mode 100644 roles/host_agent/vars/cmk_agent_generic.yml delete mode 100644 roles/host_plugins/defaults/main.yml delete mode 100644 roles/host_plugins/files/apache_status.cfg delete mode 100644 roles/host_plugins/files/ceph.cfg delete mode 100644 roles/host_plugins/files/dnsclient.cfg delete mode 100644 roles/host_plugins/files/jar_signature.cfg delete mode 100644 roles/host_plugins/files/logwatch.cfg delete mode 100644 roles/host_plugins/files/mk_oracle_cfg.ps1 delete mode 100644 roles/host_plugins/meta/main.yml delete mode 100644 roles/host_plugins/tasks/Linux-install.yml delete mode 100644 roles/host_plugins/tasks/Linux-main.yml delete mode 100644 roles/host_plugins/tasks/Linux-remove.yml delete mode 100644 roles/host_plugins/tasks/Linux-search.yml delete mode 100644 roles/host_plugins/tasks/Windows-install.yml delete mode 100644 roles/host_plugins/tasks/Windows-main.yml delete mode 100644 roles/host_plugins/tasks/Windows-remove.yml delete mode 100644 roles/host_plugins/tasks/Windows-search.yml delete mode 100644 roles/host_plugins/tasks/main.yml delete mode 100644 roles/host_plugins/vars/Linux-vars.yml delete mode 100644 roles/host_plugins/vars/Windows-vars.yml delete mode 100644 roles/host_registration/defaults/main.yml delete mode 100644 roles/host_registration/handlers/main.yml delete mode 100644 roles/host_registration/meta/main.yml delete mode 100644 roles/host_registration/tasks/main.yml diff --git a/playbooks/ansible-example.yml b/playbooks/ansible-example.yml deleted file mode 100644 index 4b2d81ea1..000000000 --- a/playbooks/ansible-example.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- hosts: g_cmk_hosts - gather_facts: smart - tags: [all, agent] - roles: - - cmk_host_agent - -- hosts: g_cmk_hosts - gather_facts: smart - tags: [all, plugins] - roles: - - cmk_host_plugins - -- hosts: g_cmk_hosts - gather_facts: smart - tags: [all, register] - roles: - - cmk_host_registration diff --git a/plugins/checkmk_changes/checkmk_changes.py b/plugins/checkmk_changes/checkmk_changes.py deleted file mode 100644 index 6d2b8faab..000000000 --- a/plugins/checkmk_changes/checkmk_changes.py +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- - -ANSIBLE_METADATA = {'status': ['preview'], - 'supported_by': 'community', - 'version': '0.1'} - -DOCUMENTATION = ''' -module: checkmk_changes - -short_description: Activate configuration changes in checkMK - -version_added: "0.1" - -description: - - "With the C(checkmk_changes) module it is possible to activate configuration changes of one or more checkMK sites." - - "This module provides some more options of the API of checkMK than the C(checkmk_host) module" - -author: "Marcel Arentz (@ma@mathias-kettner.de)" - -options: - url: - description: - - URL to the Check_MK instance as HTTP or HTTPS - required: true - user: - description: - - The user to authenticate against the site - required: true - password: - description: - - The password to authenticate against the site - required: true - sites: - description: Specifies a list of sites to activate changes on. This list may or may not contain the site on which the API call is made on. - required: false - default: none - allow_foreign_changes: - description: Sometimes other users made changes meanwhile. This option specifies if the changes should be activated if there are configuration changes from other users. - required: false - default: False - type: bool - comment: - description: You can optionally add a comment to this activation. - required: false - default: none - validate_certs: - description: Check SSL certificate - required: false - default: True - type: bool -''' - -EXAMPLES = ''' -- name: Activate changes in a single site of checkMK - checkmk_changes: - url: https://monitoring.example.org/mysite - user: myuser - password: mypassword - validate_certs: yes - -- name: Activate changes to a set of sites except the call one - checkmk_changes: - url: https://monitoring.example.org/mysite - user: myuser - password: mypassword - sites: - - first_slave_site - - second_slave_site - allow_foreign_changes: yes - comment: Changes made by ansible -''' - -RETURN = ''' -request: - - description: The paramters that was passed in - type: dict -result: - - description: The result from the Check_MK site - type: dict -''' - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.checkmk_api import Changes - -class CallChanges: - def __init__(self, session): - self.session = session - - def activate(self, payload, ansible): - result = self.session.activate(payload=payload) - result_output = result['result'] - - if 'no changes to activate' in result_output: - return False, result_output - elif isinstance(result_output, dict): - return True, result_output - - ansible.fail_json(msg='Failed to activate changes: %s' % result_output, - payload=payload) - - -def main(): - args = dict( - # Required - url=dict(type='str', required=True), - user=dict(type='str', required=True), - password=dict(type='str', required=True, no_log=True), - # Optional - sites=dict(type='list', default=None), - allow_foreign_changes=dict(type='bool', default=True), - comments=dict(type='str', default=None), - validate_certs=dict(type='bool', default=True), - ) - - ansible = AnsibleModule( - argument_spec=args, - supports_check_mode=False - ) - - sites = ansible.params['sites'] - - changes = CallChanges(Changes( - ansible.params['url'], - ansible.params['user'], - ansible.params['password'], - verify=ansible.params['validate_certs'],)) - - payload = { - 'allow_foreign_changes': '1' if ansible.params['allow_foreign_changes'] == 'yes' else '0' - } - - if ansible.params['comments']: - payload['comment'] = ansible.params['comments'] - if sites: - payload['sites'] = sites - payload['mode'] = 'specific' - else: - payload['mode'] = 'dirty' - - changed, result = changes.activate(payload, ansible) - - ansible_result = dict( - sites=sites, - changed=changed, - result=result, - ) - - ansible.exit_json(**ansible_result) - -if __name__ == '__main__': - main() diff --git a/plugins/checkmk_host/checkmk_host.py b/plugins/checkmk_host/checkmk_host.py deleted file mode 100644 index de67ff07b..000000000 --- a/plugins/checkmk_host/checkmk_host.py +++ /dev/null @@ -1,260 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- - -ANSIBLE_METADATA = {'status': ['preview'], - 'supported_by': 'community', - 'version': '0.1'} - -DOCUMENTATION = ''' -module: checkmk_host - -short_description: Managing hosts in checkMK - -version_added: "0.1" - -description: - - "With the C(checkmk_host) module it is possible to add/edit/delete hosts via the checkmk API" - -author: "Marcel Arentz (@ma@mathias-kettner.de)" - -options: - site: - description: URL to the Check_MK instance as HTTP or HTTPS. The URL just needs to have a format like C(https://myserver.com/mysite) - required: true - user: - description: The user to authenticate against the site - required: true - password: - description: The password to authenticate against the site - required: true - name: - description: Name of the host - required: true - folder: - description: Folder to put the host in. A folder is always defined as a relative path. - required: false - default: '' - attributes: - description: A host can have several attributes except it's name and the folder. These attributes are summarized in a dictionary. - required: false - state: - description: If present, the host will be created if it does not exists yet. If absent, the host will remove, if present. - required: false - default: present - choices: - - present - - absent - validate_certs: - description: Check SSL certificate - required: false - default: True - type: bool - service_discovery: - description: Start the service discovery after adding/changing the host - required: false - default: True - type: bool - activate_changes: - description: Activate the changes - required: false - default: True - type: bool -''' - -EXAMPLES = ''' -- name: Add host to Check_MK site - checkmk_host: - url: https://monitoring.example.org/mysite - user: myuser - password: mypassword - name: myhost1 - -- name: Add host with specific folder and with explcit ip address - checkmk_host: - url: https://monitoring.example.org/mysite - user: myuser - password: mypassword - name: {{ inventory_hostname }} - folder: automation/linux - attributes: - addressv4: 192.168.56.42 - alias: My Alias -''' - -RETURN = ''' -request: - - description: The paramters that was passed in - type: dict -result: - - description: The result from the Check_MK site - type: dict -service_discovery: - - description: If the services are discvored directly, the result and the result code will be available here -activate_changes: - - description: If changes are activates directly, the result and the result code will be available here - type: dict -''' - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.checkmk_api import Hosts, Services, Changes - -class CallHost: - def __init__(self, session): - self.session = session - self.hostname = session.hostname - - self.is_present, self.data = self._get(1) - - - def _get(self, effective): - host = self.session.get(effective_attributes=effective) - if isinstance(host['result'], dict): - return True, host['result'] - else: - return False, host['result'] - - - def add(self, payload): - result = self.session.add(payload=payload) - return True, result['result'] - - - def edit(self, request): - diff = False - payload = request.copy() - if payload['folder'] != self.data['path']: - self.delete() - changed, result = self.add(payload=payload) - return changed, result - payload.pop('folder') - - needed_attr = payload['attributes'] - _is_present, existing_attr = self._get(0) - existing_attr = existing_attr.get('attributes', {}) - unset_attr = [] - if not needed_attr: - if not existing_attr: - return False, None - - for key in existing_attr: - unset_attr.append(key) - - payload['unset_attributes'] = unset_attr - return True, self.session.edit(payload=payload)['result'] - else: - if not existing_attr: - return True, self.session.edit(payload=payload)['result'] - - # We need to figure what to do with every custom key - for key, value in existing_attr.items(): - if key not in needed_attr: - unset_attr.append(key) - elif value != needed_attr[key]: - diff = True - - if len(unset_attr) > 0: - payload['unset_attributes'] = unset_attr - return True, self.session.edit(payload=payload)['result'] - if diff: - return True, self.session.edit(payload=payload)['result'] - return False, None - - - def delete(self): - result = self.session.delete(payload={'hostname': self.hostname}) - return True, result['result'] - - -def main(): - args = dict( - # Required - url=dict(type='str', required=True), - user=dict(type='str', required=True), - password=dict(type='str', required=True, no_log=True), - name=dict(type='str', required=True), - # Optional - attributes=dict(type='dict', default={}), - folder=dict(type='str', default=''), - validate_certs=dict(type='bool', default=True), - discover_services=dict(type='bool', default=True), - activate_changes=dict(type='bool', default=True), - # Meta - state=dict(type='str', default='present', choices=['present', 'absent']), - ) - - ansible = AnsibleModule( - argument_spec=args, - supports_check_mode=False - ) - - hostname = ansible.params['name'] - state = ansible.params['state'] - discover = ansible.params['discover_services'] - activate = ansible.params['activate_changes'] - - host = CallHost(Hosts( - ansible.params['url'], - ansible.params['user'], - ansible.params['password'], - verify=ansible.params['validate_certs'], - hostname=hostname,)) - - payload = dict( - hostname=hostname, - folder=ansible.params['folder'], - attributes=ansible.params['attributes'] - ) - - if state == 'present' and not host.is_present: - changed, result = host.add(payload) - elif state == 'present': - changed, result = host.edit(payload) - elif state == 'absent' and host.is_present: - changed, result = host.delete() - elif state == 'absent': - changed = False - result = None - - if isinstance(result, str): - if 'exception' in result: - ansible.fail_json(msg='Failed to work on %s: %s' % (hostname, result), - request=payload, - orig_data=host.data) - - ansible_result = dict( - changed=changed, - request=payload, - result=result, - ) - - if discover and changed == True: - service = Services( - ansible.params['url'], - ansible.params['user'], - ansible.params['password'], - verify=ansible.params['validate_certs'], - hostname=hostname) - discovery = service.discover(mode='refresh') - ansible_result['service_discovery'] = dict( - result=discovery['result'], - status=discovery['result_code'], - ) - - if activate and changed == True: - changes = Changes( - ansible.params['url'], - ansible.params['user'], - ansible.params['password'], - verify=ansible.params['validate_certs']) - activation = changes.activate(allow_foreign_changes=1) - ansible_result['activate_changes'] = dict( - result=activation['result'], - status=activation['result_code'], - ) - - ansible_result['hostname'] = hostname - ansible.exit_json(**ansible_result) - -if __name__ == '__main__': - main() diff --git a/plugins/checkmk_services/checkmk_services.py b/plugins/checkmk_services/checkmk_services.py deleted file mode 100644 index 282e08ffd..000000000 --- a/plugins/checkmk_services/checkmk_services.py +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- - -ANSIBLE_METADATA = {'status': ['preview'], - 'supported_by': 'community', - 'version': '0.1'} - -DOCUMENTATION = ''' -module: checkmk_services - -short_description: Managing services in checkMK - -version_added: "0.1" - -description: - - "With the C(checkmk_services) module it is possible to discover or rediscover services of a host in checkMK." - - "This module provides some more options of the API of checkMK than the C(checkmk_host) module" - -author: "Marcel Arentz (@ma@mathias-kettner.de)" - -options: - site: - description: - - URL to the Check_MK instance as HTTP or HTTPS - required: true - user: - description: - - The user to authenticate against the site - required: true - password: - description: - - The password to authenticate against the site - required: true - name: - description: Name of the host - required: true - mode: - description: Controls the behaviour of the service discovery. With C(new) all new services are added to the host while C(remove) just removes vanished services. You can combine these two mode with C(fixall). C(refresh) removes all services and rediscvors them again afterwards. - required: false - default: new - choices: - - fixall - - new - - refresh - - remove - validate_certs: - description: Check SSL certificate - required: false - default: True - type: bool -''' - -EXAMPLES = ''' -- name: Add new services to a host in checkMK - checkmk_services: - url: https://monitoring.example.org/mysite - user: myuser - password: mypassword - name: myhost1 - -- name: Adds new and removes vanished services - checkmk_services: - url: https://monitoring.example.org/mysite - user: myuser - password: mypassword - name: {{ inventory_hostname }} - mode: fixall -''' - -RETURN = ''' -request: - - description: The paramters that was passed in - type: dict -result: - - description: The result from the Check_MK site - type: dict -''' - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.checkmk_api import Services - -class CallServices: - def __init__(self, session): - self.session = session - self.hostname = session.hostname - - - def discover(self, mode): - result = self.session.discover(mode=mode) - result_text = result['result'] - - if result_text.startswith('Service discovery successful.'): - list_as_string = result.text.strip('Service discovery successful.') - added, removed, kept, new_count = list_as_string.split(',') - added_count = int(added.split(' ')[1]) - removed_count = int(removed.split(' ')[1]) - - if added_count > 0 or removed_count > 0: - return True, result_text - return False, result_text - - ansible.fail_json(msg='Failed to discover as %s: %s' % (mode, result_text)) - -def main(): - args = dict( - # Required - url=dict(type='str', required=True), - user=dict(type='str', required=True), - password=dict(type='str', required=True, no_log=True), - name=dict(type='str', required=True), - # Optional - mode=dict(type='str', default='new', choices=['']), - validate_certs=dict(type='bool', default=True), - ) - - ansible = AnsibleModule( - argument_spec=args, - supports_check_mode=False - ) - - hostname = ansible.params['name'] - mode = ansible.params['mode'] - - host = CallServices(Services( - ansible.params['url'], - ansible.params['user'], - ansible.params['password'], - verify=ansible.params['validate_certs'], - hostname=hostname,)) - - changed, result = host.discover(mode=mode) - - ansible_result = dict( - hostname=hostname, - changed=changed, - mode=mode, - result=result, - ) - - ansible.exit_json(**ansible_result) - -if __name__ == '__main__': - main() diff --git a/plugins/modules/checkmk_api.py b/plugins/modules/checkmk_api.py deleted file mode 100644 index 0a6528edf..000000000 --- a/plugins/modules/checkmk_api.py +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- - -from collections import namedtuple -import ast -import requests - - -class WebAPI(object): - def __init__(self, session): - self.url = session.url - self.username = session.username - self.secret = session.secret - self.verify = session.verify - - self.header = { - 'request_format': 'python', - 'output_format': 'python', - '_username': self.username, - '_secret': self.secret, - } - - def query(self, action, request=None): - payload = self.header.copy() - payload['action'] = action - if request: - payload['request'] = repr(request) - - try: - response = requests.get(self.url, params=payload, verify=self.verify, timeout=30) - return ast.literal_eval(response.text) - except: - raise - - @property - def result(self): - return self.result - - @property - def result_code(self): - return self.result_code - - -class DataTuple(object): - def __init__(self, url, username, secret, verify=True): - name = namedtuple('name', ['url', 'username', 'secret', 'verify']) - self.data = name(url, username, secret, verify) - - -class Hosts(object): - def __init__(self, url, username, secret, verify=True, hostname=None): - url = "%s/check_mk/webapi.py" % url.rstrip('/') - session = DataTuple(url, username, secret, verify) - self.session = WebAPI(session.data) - self.hostname = hostname - - def _prepare_hostname(self, hostname=None): - if hostname: - self.hostname = hostname - - def pre_call(name): - def _build_payload(fn): - def _decorator(self, **kwargs): - self._prepare_hostname(kwargs.get('hostname', None)) - if not self.hostname: - return fn(self, payload=None) - - if kwargs.get('payload', None): - payload = kwargs['payload'] - else: # we need to build the payload manually - payload = {'hostname': self.hostname} - if name == 'get': - payload['effective_attributes'] = kwargs.get('effective_attributes', 0) - if name in ['add', 'edit'] and kwargs.get('attributes', None): - payload['attributes'] = kwargs['attributes'] - if name == 'add': - payload['folder'] = kwargs.get('folder', '') - - return fn(self, payload=payload) - return _decorator - return _build_payload - - @pre_call('get') - def get(self, hostname=None, effective_attributes=None, payload=None): - return self.session.query('get_host', payload) - - @pre_call('add') - def add(self, hostname=None, folder=None, attributes=None, payload=None): - return self.session.query('add_host', payload) - - @pre_call('delete') - def delete(self, hostname=None, payload=None): - return self.session.query('delete_host', payload) - - @pre_call('edit') - def edit(self, hostname=None, attributes=None, payload=None): - return self.session.query('edit_host', payload) - - -class Services(object): - def __init__(self, url, username, secret, verify=True, hostname=None): - url = "%s/check_mk/webapi.py" % url.rstrip('/') - session = DataTuple(url, username, secret, verify) - self.session = WebAPI(session.data) - self.hostname = hostname - - - def _prepare_hostname(self, hostname=None): - if hostname: - self.hostname = hostname - - def pre_call(fn): - def _decorator(self, *args, **kwargs): - self._prepare_hostname(kwargs.get('hostname', None)) - if not self.hostname: - return fn(self, payload=None) - - if kwargs.get('payload', None): - payload = kwargs['payload'] - else: - payload = {'hostname': self.hostname} - if kwargs.get('mode', None): - payload['mode'] = kwargs['mode'] - - return fn(self, payload=payload) - return _decorator - - @pre_call - def discover(self, hostname=None, mode=None, payload=None): - return self.session.query('discover_services', payload) - - -class Changes(object): - def __init__(self, url, username, secret, verify=True): - url = "%s/check_mk/webapi.py" % url.rstrip('/') - session = DataTuple(url, username, secret, verify) - self.session = WebAPI(session.data) - - def pre_call(fn): - def _decorator(self, **kwargs): - if kwargs.get('payload', None): - payload = kwargs['payload'] - else: - payload = {} - if kwargs.get('sites', None): - payload['mode'] = 'specific' - payload['sites'] = list(kwargs['sites']) - if kwargs.get('allow_foreign_changes', None): - payload['allow_foreign_changes'] = str(kwargs['allow_foreign_changes']) - if kwargs.get('comment', None): - payload['comment'] = str(kwargs['comment']) - return fn(self, payload=payload) - return _decorator - - @pre_call - def activate(self, sites=None, allow_foreign_changes=None, comment=None, payload=None): - return self.session.query('activate_changes', payload) diff --git a/roles/host_agent/defaults/main.yml b/roles/host_agent/defaults/main.yml deleted file mode 100644 index 3671a0fd1..000000000 --- a/roles/host_agent/defaults/main.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -# Site variables -cmk_version: "1.5.0p13" -cmk_site_url: "http://192.168.56.1/mysite" - -# temp directories for files -cmk_host_linux_tmp: "/tmp" -cmk_host_windows_tmp: "C:\\Users\\{{ ansible_user }}\\AppData\\Local\\Temp" - diff --git a/roles/host_agent/files/check_mk.ini b/roles/host_agent/files/check_mk.ini deleted file mode 100644 index 8bf57b74f..000000000 --- a/roles/host_agent/files/check_mk.ini +++ /dev/null @@ -1,222 +0,0 @@ -# Example configuration for Windows agent -[global] - # Restrict access to certain IP addresses - # If ipv6 is enabled, all listed ipv4 adresses are also accepted as - # source adresses in their ipv6-mapped form. I.e. if - # 192.168.56.0/24 is listed, connections from ::ffff:c0a8:3800/120 - # are also possible - # only_from = 127.0.0.1 192.168.56.0/24 ::1 - - # Change port where the agent is listening ( default 6556 ) - # port = 6556 - - # Disable ipv6 support. By default, ipv4 is always supported - # and ipv6 is enabled additionally if supported by the system. - # ipv6 = no - - # Do only execute programs and scripts with - # the following suffixes (in local and plugins). - # Per default all extensions except txt and dir - # are being executed. - # execute = exe bat vbs - - # Run async scripts in parallel (to each other). Default is "sequential", - # which means the scripts are run asynchronously to the agent itself but - # one after the other. Setting this to parallel may improve the delay before - # new data is reported but may also lead to the agent having more noticable - # impact on the system performance - # async_script_execution = parallel - - # Restrict the following configuration variables - # in [global] to the following hosts - # host = winsrv* zab???ad - - # Just output certain sections (e.g. for upper hosts) - # sections = check_mk winperf - - # Disable specific sections (overrules sections parameter) - # disabled_sections = logfiles - - # output sections in realtime updates. Please note that not all - # sections can be used in realtime updates, the following is the - # complete list - # realtime_sections = mem df winperf_processor - - # specifies how long (in seconds) realtime updates are sent to - # the last monitoring system that requested an update. - # this should be longer than the request frequency (usually - # one minute). - # Please note that any new request cancels previous realtime - # update schedules, so no more than one update is sent per second, - # no matter if this timeout is "too high" or how many monitoring - # systems are querying the agent. - # realtime_timeout = 90 - - # enable/disable encryption of regular agent output (default: disabled) - # encrypted = yes - - # enable/disable encryption of realtime updates (default: enabled) - # encrypted = yes - - # passphrase for encrypted communication. - # passphrase = secret - - # Write a logfile for tackling down crashes of the agent - # crash_debug = yes - - # by default the agent flushes the socket for each agent section. - # this is mostly for debugging purposes in case the agent is slow - # to respond. - # Disabling this may (very) slightly reduce network traffic. - # section_flush = no - -[winperf] - # Select counters to extract. The following counters - # are needed by checks shipped with check_mk. - # counters = 10332:msx_queues - # counters = 638:tcp_conn - - # Instead of specifying the counter start index, the name of the performance - # counter can be used. - # counters = Terminal Services:ts_sessions - -[logfiles] - # # Define textfiles to be monitored, separated by | - # textfile = C:\tmp logfiles\message_*.log|D:\log\sample.txt - # # Set patterns for defined textfiles - # ok = Successfully logged in* - # crit = Error in* - # warn = Unable to contact* - # ignore = Backup * saved - - # # Define additional textfiles with different patterns - # textfile = C:\tmp\memo.udf - # # Set patterns for defined textfile - # warn = *overdue* - # ok = *mail sent* - - # # handling of the log can be customized through tags prepended to the name - # # - # # don't send context lines around relevant lines - # textfile = nocontext d:\log\sample.txt - # # read new files from the first line. Otherwise the agent will start at the - # # last line at the time the agent first sees the file - # textfile = from_start d:\log\sample*.txt - # # treat the file as a rotated log (one where in certain intervals a new file is - # # created and the previous file is at some point moved away). - # # In this case all files matching this pattern are treated as one service - # # and the agent will try to read each file to the end and then continue to the - # # next newer one. - # textfile = rotated d:\log\sample_*.txt - # # Of course these tags can be combined - # textfile = nocontext rotated d:\log\sample_*.txt - -[logwatch] - # activate modern eventlog api introduced in vista - # pro: supports new logs introduced with vista - # contra: only on vista (server 2008) and newer, less well tested, maybe slower - # Note: setting this does not change the default set of monitored logs that - # are found in Windows registry. - # vista_api = yes - - # Testing: output *all* messages from the eventlogs - # sendall = yes - - # From application log send only critical messages - # logfile application = crit - - # From system log send only warning/critical messages, - # but suppress any context messages - # logfile system = nocontext warn - - # Switch all other logfiles off. Default is warn: - # send messages of type warn or crit - # logfile * = off - - # Activate a specific log. Requires vista_api = yes. This can be used to - # activate the monitoring of a log not found in Windows registry. Note: - # wildcards only work with standard logs that are found in Windows registry. - # To find the correct name for a log, right-click on the log in - # event-viewer -> Properties and use the name from "Full Name" - # logfile Microsoft-Windows-GroupPolicy/Operational = warn - -[mrpe] - # Run classical monitoring plugins. The word before the command - # line is the service description for the monitoring. Use backslashes - # in Windows-paths. - # Note: The windows agent will prefix all commands without an absolute - # path with the agents executable dir. So if you want to use - # system wide commands like cscript or ping, you need to specify - # them with an absolute path - # check = Dummy mrpe\check_crit - # check = IP_Configuration mrpe\check_ipconfig 1.2.3.4 - # check = Whatever c:\myplugins\check_whatever -w 10 -c 20 - # - # The option include allows you to define additional include files and the - # user domain in which include files should be executed. - # - # include \\exampleuser = C:\includes\exampleuser_mrpe.cfg - # - # If you omit the user the file is executed with the current user - # - # include = C:\includes\default.cfg - # - # The syntax in the mrpe include file is the same as in the mrpe section, - # with the exception that you cannot add further includes in a include file. - # There is also no need to define a [mrpe] section in an included file. You - # just need to define the check lines here. - # - # exampleuser_mrpe.cfg - # check = Dummy mrpe\check_crit - # check = IP_Configuration mrpe\check_ipconfig 1.2.3.4 - # - # # Paths or plugin parameters containing spaces must be quoted: - # check = Dummy "C:\Program Files (x86)\check_mk\mrpe\check_crit.bat" - # some param "with space" - # - # Important: Keep in mind that the agent needs the permission to run - # scripts as other user. Internally it uses the windows command runas /User: - # which prompts for a password if agent has no permission to change to this user. - # In this case the check_mk agent will get stuck! - -[fileinfo] - # path = C:\Programs\Foo\*.log - # path = M:\Bar Test\*.* - # Recursive wildcards can also be used: - # path = C:\MyDocuments\Foo\** - -[local] - # define timeouts for local scripts matching - # specific patterns - first match wins - # timeout *.vbs = 20 - # timeout *.bat = 10 - # timeout * = 30 - -[plugins] - # example: the windows_updates.vbs - # plugin is executed asynchronous - # and is only updated every 3600 seconds - # it may fail (timeout / error) up to 3 times before the last known data is discarded - # execution windows_updates.vbs = async - # timeout windows_updates.vbs = 120 - # cache_age windows_updates.vbs = 3600 - # retry_count windows_updates.vbs = 3 - - # define timeouts for plugin scripts matching - # specific patterns - first match wins - # timeout ps_perf.ps1 = 20 - # timeout *.ps1 = 10 - # timeout * = 30 - - # When using the Check_MK Inventory plugin, it is a good idea to make the - # plugin being executed asynchronous to prevent it from hooking up the - # whole agent processing. Additionally it should have a execution timeout. - # execution mk_inventory.ps1 = async - # timeout mk_inventory.ps1 = 240 - -[ps] - # Experimental: Set to yes to use wmi for retrieving process information. - # This is required for the additional ps feature below. - # use_wmi = no - # Include the whole path of a process and its arguments in the process list. - # full_path = no diff --git a/roles/host_agent/meta/main.yml b/roles/host_agent/meta/main.yml deleted file mode 100644 index 761669c0e..000000000 --- a/roles/host_agent/meta/main.yml +++ /dev/null @@ -1,9 +0,0 @@ -galaxy_info: - role_name: cmk_host_agent - author: Marcel Arentz - description: Installing and updating checkMK agents - company: tribe29 GmbH - - license: GPLv2 - - min_ansible_version: 2.4 diff --git a/roles/host_agent/tasks/Debian-tasks.yml b/roles/host_agent/tasks/Debian-tasks.yml deleted file mode 100644 index 372c8d892..000000000 --- a/roles/host_agent/tasks/Debian-tasks.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# Install Check_MK Agent on Debian/Ubuntu - -- name: Download agent -> {{ cmk_agent.url.deb }} - get_url: - url: "{{ cmk_agent.url.deb }}" - dest: "{{ cmk_host_linux_tmp }}" - -- name: Install agent -> {{ cmk_agent.file.deb }} - become: yes - apt: - deb: "{{ cmk_agent.file.deb }}" - state: present diff --git a/roles/host_agent/tasks/RedHat-tasks.yml b/roles/host_agent/tasks/RedHat-tasks.yml deleted file mode 100644 index 7f3dc3796..000000000 --- a/roles/host_agent/tasks/RedHat-tasks.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -# Install Check_MK Agent on RedHat/CentOS/Fedora - -- name: Download agent -> {{ cmk_agent.url.rpm }} - get_url: - url: "{{ cmk_agent.url.rpm }}" - dest: "{{ cmk_host_linux_tmp }}" - -- name: Install agent -> {{ cmk_agent.file.rpm }} - become: yes - yum: - name: "{{ cmk_agent.file.rpm }}" - state: present - disable_gpg_check: yes diff --git a/roles/host_agent/tasks/Windows-tasks.yml b/roles/host_agent/tasks/Windows-tasks.yml deleted file mode 100644 index 63ae77bb4..000000000 --- a/roles/host_agent/tasks/Windows-tasks.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -# Install Check_MK Agent on Windows - -- name: Get current agent version - win_shell: | - $cmk = "C:\Program Files (x86)\check_mk\check_mk_agent.exe" - If (Test-Path $cmk) { - (Get-Item $cmk).VersionInfo.ProductVersion - } Else { - "No agent installed"} - register: cmk_agent_version - changed_when: cmk_agent_version.stdout_lines[0] != cmk_version - -- name: Download agent -> {{ cmk_agent.url.win }} - win_get_url: - url: "{{ cmk_agent.url.win }}" - dest: "{{ cmk_host_windows_tmp }}" - when: cmk_agent_version.changed - -- name: Install agent -> {{ cmk_agent.file.win }} - win_package: - path: "{{ cmk_agent.file.win }}" - state: present - wait: True - when: cmk_agent_version.changed - -- name: Install agent config - win_copy: - src: "check_mk.ini" - dest: "{{ cmk_agent.file.win_conf }}" diff --git a/roles/host_agent/tasks/main.yml b/roles/host_agent/tasks/main.yml deleted file mode 100644 index af550f498..000000000 --- a/roles/host_agent/tasks/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -#- include_vars: cmk_agent_win.yml -- include_vars: cmk_agent_generic.yml -- include_tasks: "{{ ansible_os_family }}-tasks.yml" diff --git a/roles/host_agent/vars/cmk_agent_generic.yml b/roles/host_agent/vars/cmk_agent_generic.yml deleted file mode 100644 index af133b629..000000000 --- a/roles/host_agent/vars/cmk_agent_generic.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -cmk_agent: - url: - deb: "{{ cmk_site_url }}/check_mk/agents/check-mk-agent_{{ cmk_version }}-1_all.deb" - rpm: "{{ cmk_site_url }}/check_mk/agents/check-mk-agent-{{ cmk_version }}-1.noarch.rpm" - win: "{{ cmk_site_url }}/check_mk/agents/windows/check_mk_agent.msi" - win_conf: "check_mk.ini" - file: - deb: "{{ cmk_host_linux_tmp }}/check-mk-agent_{{ cmk_version }}-1_all.deb" - rpm: "{{ cmk_host_linux_tmp }}/check-mk-agent-{{ cmk_version }}-1.noarch.rpm" - win: "{{ cmk_host_windows_tmp }}\\check_mk_agent.msi" - win_conf: "C:\\Program Files (x86)\\check_mk\\check_mk.ini" diff --git a/roles/host_plugins/defaults/main.yml b/roles/host_plugins/defaults/main.yml deleted file mode 100644 index 8d47171be..000000000 --- a/roles/host_plugins/defaults/main.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- -# General variables -cmk_site_url: "http://192.168.56.1/mysite" -cmk_agent_lnx_path: "/usr/lib/check_mk_agent" -cmk_agent_win_path: "C:\\Program Files (x86)\\check_mk" - -# Set optional search methods -by_process: true -by_package: false -by_files: false - - -# Definition of plugins -# Example definition (none option is mandatory): -# apache_status: -# cmd: apache2 -> regex for process match -# pkg: apache2 -> exact name of package -# cfg: apache_status.cfg -> config file if the plugin needs one -# path: /usr/sbin/apache2 -> path to file for match -# force: true -> true/false to enforce the presence - -cmk_host_plugins: - Linux: - apache_status: - cmd: apache - pkg: apache2 - cfg: apache_status.cfg - asmcmd.sh: - force: false - db2_mem: - cmd: db2sysc - dnsclient: - force: false - isc_dhcpd: - cmd: dhcpd - path: /etc/dhcp/dhcpd.conf - jar_signature: - path: /home/oracle/bin/jdk_latest_version - cfg: jar_signature.cfg - kaspersky_av: - path: /opt/kaspersky/kav4fs/bin/kav4fs-control - lnx_quota: - path: /usr/sbin/repquota - lvm: - pkg: lvm2 - mailman_lists: - pkg: mailman - mk_apt: - path: /usr/bin/apt - mk_ceph: - cmd: ceph - cfg: ceph.cfg - mk_cups_queues: - cmd: cups - path: /usr/bin/lpstat - pkg: cups - mk_db2.linux: - cmd: db2wdog - mk_filehandler: - force: false - mk_docker_node: - cmd: docker - pkg: docker-ce - mk_docker_container_piggybacked: - cmd: docker - pkg: docker-ce - mk_logwatch: - cfg: logwatch.cfg - force: false - mk_logins: - force: true - mk_oracle: - cmd: oracle - cfg: mk_oracle.cfg - Windows: - mk_oracle.ps1: - cmd: oracle - cfg: mk_oracle_cfg.ps1 diff --git a/roles/host_plugins/files/apache_status.cfg b/roles/host_plugins/files/apache_status.cfg deleted file mode 100644 index c2b14483d..000000000 --- a/roles/host_plugins/files/apache_status.cfg +++ /dev/null @@ -1,47 +0,0 @@ -# +------------------------------------------------------------------+ -# | ____ _ _ __ __ _ __ | -# | / ___| |__ ___ ___| | __ | \/ | |/ / | -# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | -# | | |___| | | | __/ (__| < | | | | . \ | -# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | -# | | -# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de | -# +------------------------------------------------------------------+ -# -# This file is part of Check_MK. -# The official homepage is at http://mathias-kettner.de/check_mk. -# -# check_mk is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation in version 2. check_mk is distributed -# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- -# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more de- -# tails. You should have received a copy of the GNU General Public -# License along with GNU Make; see the file COPYING. If not, write -# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -# Boston, MA 02110-1301 USA. - -# Example for configuration for apache_status plugin -# Note: you need this file only if the autodetection fails -# or you do not want to contact all servers it detects - -# Note: Activate this only if the autodetection fails. -#servers = [ -#{ -# 'protocol' : 'http', -# 'address' : 'localhost', -# 'port' : 80 , -#}, -#{ -# 'protocol' : 'http', -# 'address' : 'localhost', -# 'port' : 8080 , -#}, -#{ -# 'protocol' : 'https', -# 'address' : 'localhost', -# 'port' : 443 , -#}, -#] - diff --git a/roles/host_plugins/files/ceph.cfg b/roles/host_plugins/files/ceph.cfg deleted file mode 100644 index cc7d335c9..000000000 --- a/roles/host_plugins/files/ceph.cfg +++ /dev/null @@ -1,2 +0,0 @@ -USER=client.admin -KEYRING=/etc/ceph/ceph.client.admin.keyring diff --git a/roles/host_plugins/files/dnsclient.cfg b/roles/host_plugins/files/dnsclient.cfg deleted file mode 100644 index 29c98098c..000000000 --- a/roles/host_plugins/files/dnsclient.cfg +++ /dev/null @@ -1 +0,0 @@ -HOSTADDRESS=mathias-kettner.de diff --git a/roles/host_plugins/files/jar_signature.cfg b/roles/host_plugins/files/jar_signature.cfg deleted file mode 100644 index 8f6547d84..000000000 --- a/roles/host_plugins/files/jar_signature.cfg +++ /dev/null @@ -1,2 +0,0 @@ -JAVA_HOME=/home/oracle/bin/jdk_latest_version -JAR_PATH=/home/oracle/fmw/11gR2/as_1/forms/java/*.jar diff --git a/roles/host_plugins/files/logwatch.cfg b/roles/host_plugins/files/logwatch.cfg deleted file mode 100644 index f06f72b8f..000000000 --- a/roles/host_plugins/files/logwatch.cfg +++ /dev/null @@ -1,59 +0,0 @@ -# +------------------------------------------------------------------+ -# | ____ _ _ __ __ _ __ | -# | / ___| |__ ___ ___| | __ | \/ | |/ / | -# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | -# | | |___| | | | __/ (__| < | | | | . \ | -# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | -# | | -# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de | -# +------------------------------------------------------------------+ -# -# This file is part of Check_MK. -# The official homepage is at http://mathias-kettner.de/check_mk. -# -# check_mk is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation in version 2. check_mk is distributed -# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- -# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more de- -# tails. You should have received a copy of the GNU General Public -# License along with GNU Make; see the file COPYING. If not, write -# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -# Boston, MA 02110-1301 USA. - -# logwatch.cfg -# This file configures mk_logwatch. Define your logfiles -# and patterns to be looked for here. - -# Name one or more logfiles -/var/log/messages -# Patterns are indented with one space are prefixed with: -# C: Critical messages -# W: Warning messages -# I: ignore these lines (OK) -# R: Rewrite the output previous match. You can use \1, \2 etc. for refer to groups (.*) of this match -# The first match decided. Lines that do not match any pattern -# are ignored - C Fail event detected on md device - I mdadm.*: Rebuild.*event detected - W mdadm\[ - W ata.*hard resetting link - W ata.*soft reset failed (.*FIS failed) - W device-mapper: thin:.*reached low water mark - C device-mapper: thin:.*no free space - C Error: (.*) - -/var/log/auth.log - W sshd.*Corrupted MAC on input - -/var/log/syslog /var/log/kern.log - I registered panic notifier - C panic - C Oops - W generic protection rip - W .*Unrecovered read error - auto reallocate failed - -# Globbing patterns are allowed: -# /sapdata/*/saptrans.log -# C ORA- diff --git a/roles/host_plugins/files/mk_oracle_cfg.ps1 b/roles/host_plugins/files/mk_oracle_cfg.ps1 deleted file mode 100644 index 5c5c7850a..000000000 --- a/roles/host_plugins/files/mk_oracle_cfg.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -# Example configuration for ORACLE plugin for Windows -# Set the ORACLE_HOME if we have more than one oracle home on the server -# then we can generate the PATH based on that. Note that the tnsnames.ora -# must then be in %ORACLE_HOME%\network\admin, or use the the environment -# variable %TBS_ADMIN% to set to another directory. -# $ORACLE_HOME="C:\oracle\product\12.1.0.1" - -# $DBUSER=@("sys", "Secret12", "SYSDBA", "localhost", "1521") -# $DBUSER_tst=@("sys", "Secret12", "SYSDBA", "localhost", "1521") -# $DBUSER_orcl=@("sys", "Secret12", "SYSDBA", "localhost", "1521") -# $DBUSER_orcl=@("sys", "Secret12", "SYSDBA", "localhost", "1521") -# $ASMUSER=@("user", "password", "SYSDBA/SYSASM", "hostname", "port") - diff --git a/roles/host_plugins/meta/main.yml b/roles/host_plugins/meta/main.yml deleted file mode 100644 index 03022e2a7..000000000 --- a/roles/host_plugins/meta/main.yml +++ /dev/null @@ -1,9 +0,0 @@ -galaxy_info: - role_name: cmk_host_plugins - author: Marcel Arentz - description: Installing and updating checkMK agent plugins - company: tribe29 GmbH - - license: GPLv2 - - min_ansible_version: 2.4 diff --git a/roles/host_plugins/tasks/Linux-install.yml b/roles/host_plugins/tasks/Linux-install.yml deleted file mode 100644 index ec357440e..000000000 --- a/roles/host_plugins/tasks/Linux-install.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- - -- name: Install {{ needed_plugin }} - get_url: - url: "{{ cmk_site_url }}/check_mk/agents/plugins/{{ needed_plugin }}" - dest: "{{ plugins_path }}/{{ needed_plugin }}" - owner: root - group: root - mode: 0500 # Prevent users from editing this script on the host - -- name: Install config file for {{ needed_plugin }} - copy: - src: "{{ cmk_plugin_base[ needed_plugin ].cfg }}" - dest: "{{ config_path }}/{{ cmk_plugin_base[ needed_plugin ].cfg }}" - owner: root - group: root - mode: 0400 # Prevent users from editing this file on the host - when: cmk_plugin_base[ needed_plugin ].cfg is defined diff --git a/roles/host_plugins/tasks/Linux-main.yml b/roles/host_plugins/tasks/Linux-main.yml deleted file mode 100644 index f16cd427a..000000000 --- a/roles/host_plugins/tasks/Linux-main.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- - -- name: Get installed plugins - shell: "ls {{ plugins_path }}/" - register: plugin_list - changed_when: false - -- package_facts: - when: by_package == true - -- include_tasks: "Linux-search.yml" - with_dict: "{{ cmk_plugin_base }}" - loop_control: - loop_var: plugin_name - -- include_tasks: "Linux-install.yml" - with_items: "{{ CMK_PLUGINS }}" - loop_control: - loop_var: needed_plugin - when: CMK_PLUGINS|length > 0 - -- name: Get obsolete installed Plugins - set_fact: - plugin_list: "{{ plugin_list.stdout_lines | difference(CMK_PLUGINS) }}" - -- include_tasks: "Linux-remove.yml" - with_items: "{{ plugin_list }}" - loop_control: - loop_var: obsolete_plugin - when: obsolete_plugin|length > 0 - diff --git a/roles/host_plugins/tasks/Linux-remove.yml b/roles/host_plugins/tasks/Linux-remove.yml deleted file mode 100644 index 62389f827..000000000 --- a/roles/host_plugins/tasks/Linux-remove.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- - -- name: Remove obsolete {{ obsolete_plugin }} - file: - path: "{{ plugins_path }}/{{ obsolete_plugin }}" - state: absent - -- name: Remove obsolete config of {{ obsolete_plugin }} - file: - path: "{{ config_path }}/{{ cmk_plugin_base[ obsolete_plugin ].cfg }}" - state: absent - when: cmk_plugin_base[ obsolete_plugin ].cfg is defined diff --git a/roles/host_plugins/tasks/Linux-search.yml b/roles/host_plugins/tasks/Linux-search.yml deleted file mode 100644 index 5aec2774c..000000000 --- a/roles/host_plugins/tasks/Linux-search.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- - -- name: Get process needed for {{ plugin_name.key }} - shell: "pgrep -c {{ plugin_name.value.cmd }}" - register: get_process - failed_when: get_process.stdout == "" - changed_when: false - when: by_process == true and plugin_name.value.cmd is defined - -- name: Get file needed for {{ plugin_name.key }} - stat: - path: "{{ plugin_name.value.path }}" - register: get_file - changed_when: false - when: by_files == true and plugin_name.value.path is defined - -- name: Add {{ plugin_name.key }} to needed plugins - set_fact: - CMK_PLUGINS: "{{ CMK_PLUGINS + [ plugin_name.key ] }}" - when: (get_process.rc is defined and get_process.rc == 0) or - (get_file.stat is defined and get_file.stat.exists == true) or - (by_package == true and plugin_name.value.pkg is defined and plugin_name.value.pkg in packages) or - (plugin_name.value.force is defined and plugin_name.value.force == true) diff --git a/roles/host_plugins/tasks/Windows-install.yml b/roles/host_plugins/tasks/Windows-install.yml deleted file mode 100644 index 87d8089a1..000000000 --- a/roles/host_plugins/tasks/Windows-install.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- - -- name: Install {{ needed_plugin }} - win_get_url: - url: "{{ cmk_site_url }}/check_mk/agents/windows/plugins/{{ needed_plugin }}" - dest: "{{ plugins_path }}/{{ needed_plugin }}" - -- name: Install config file for {{ needed_plugin }} - win_copy: - src: "{{ cmk_plugin_base[ needed_plugin ].cfg }}" - dest: "{{ config_path }}/{{ cmk_plugin_base[ needed_plugin ].cfg }}" - when: cmk_plugin_base[ needed_plugin ].cfg is defined diff --git a/roles/host_plugins/tasks/Windows-main.yml b/roles/host_plugins/tasks/Windows-main.yml deleted file mode 100644 index 4c7e74776..000000000 --- a/roles/host_plugins/tasks/Windows-main.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- - -- name: Get installed plugins - win_shell: "(Get-Item '{{ plugins_path }}\\*' | Select-Object Name | Format-Table -HideTableHeaders | Out-String).trim()" - register: plugin_list - changed_when: false - -- name: Get installed software - win_shell: "(Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName | Format-Table -HideTableHeaders | Out-String).trim()" - register: software_list - when: by_package == true - -- include_tasks: "Windows-search.yml" - with_dict: "{{ cmk_plugin_base }}" - loop_control: - loop_var: plugin_name - -- include_tasks: "Windows-install.yml" - with_items: "{{ CMK_PLUGINS }}" - loop_control: - loop_var: needed_plugin - when: CMK_PLUGINS > 0 - -- name: Get obsolete installed Plugins - set_fact: - plugin_list: "{{ plugin_list.stdout_lines | difference(CMK_PLUGINS) }}" - -- include_tasks: "Windows-remove.yml" - with_items: "{{ plugin_list }}" - loop_control: - loop_var: obsolete_plugin - when: obsolete_plugin > 0 and obsolete_plugin != "" diff --git a/roles/host_plugins/tasks/Windows-remove.yml b/roles/host_plugins/tasks/Windows-remove.yml deleted file mode 100644 index 817638294..000000000 --- a/roles/host_plugins/tasks/Windows-remove.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- - -- name: Remove obsolete {{ obsolete_plugin }} - win_file: - path: "{{ plugins_path }}/{{ obsolete_plugin }}" - state: absent - -- name: Remove obsolete config of {{ obsolete_plugin }} - win_file: - path: "{{ config_path }}/{{ cmk_plugin_base[ obsolete_plugin ].cfg }}" - state: absent - when: cmk_plugin_base[ obsolete_plugin ].cfg is defined diff --git a/roles/host_plugins/tasks/Windows-search.yml b/roles/host_plugins/tasks/Windows-search.yml deleted file mode 100644 index 68673da9b..000000000 --- a/roles/host_plugins/tasks/Windows-search.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- - -- name: Get process needed for {{ plugin_name.key }} - win_shell: "(Get-Process | Where-Object {$_.ProcessName -like '*{{ plugin_name.value.cmd }}*'} | Get-Unique | Select-Object ProcessName | Format-Table -HideTableHeaders | Out-String).trim()" - register: get_process - failed_when: get_process.rc == 1 - changed_when: false - when: by_process == true and plugin_name.value.cmd is defined - -- name: Get file needed for {{ plugin_name.key }} - win_stat: - path: "{{ plugin_name.value.path }}" - register: get_file - changed_when: false - when: by_files == true and plugin_name.value.path is defined - -- name: Add {{ plugin_name.key }} to needed plugins - set_fact: - CMK_PLUGINS: "{{ CMK_PLUGINS + [ plugin_name.key ] }}" - when: (get_process.stdout is defined and get_process.stdout_lines[0] != "" ) or - (get_file.stat is defined and get_file.stat.exists == true) or - (by_package == true and plugin_name.value.pkg is defined and plugin_name.value.pkg in packages) or - (plugin_name.value.force is defined and plugin_name.value.force == true) diff --git a/roles/host_plugins/tasks/main.yml b/roles/host_plugins/tasks/main.yml deleted file mode 100644 index d6df112d4..000000000 --- a/roles/host_plugins/tasks/main.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- - -# Initialize list of plugins/configs to install - -- set_fact: - OS: "Linux" - when: ansible_system == "Linux" - -- set_fact: - OS: "Windows" - when: ansible_os_family == "Windows" - -- set_fact: - CMK_PLUGINS: [ ] - cmk_plugin_base: "{{ cmk_host_plugins[ OS ] }}" - -# Install plugins based on OS system -- include_vars: "{{ OS }}-vars.yml" -- include_tasks: "{{ OS }}-main.yml" diff --git a/roles/host_plugins/vars/Linux-vars.yml b/roles/host_plugins/vars/Linux-vars.yml deleted file mode 100644 index a1588589d..000000000 --- a/roles/host_plugins/vars/Linux-vars.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- - -plugins_path: "{{ cmk_agent_lnx_path }}/plugins" -local_path: "{{ cmk_agent_lnx_path }}/local" -config_path: "/etc/check_mk/" diff --git a/roles/host_plugins/vars/Windows-vars.yml b/roles/host_plugins/vars/Windows-vars.yml deleted file mode 100644 index 29f7385d5..000000000 --- a/roles/host_plugins/vars/Windows-vars.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- - -plugins_path: "{{ cmk_agent_win_path }}\\plugins" -local_path: "{{ cmk_agent_win_path }}\\local" -config_path: "{{ cmk_agent_win_path }}\\config" diff --git a/roles/host_registration/defaults/main.yml b/roles/host_registration/defaults/main.yml deleted file mode 100644 index 2822056a8..000000000 --- a/roles/host_registration/defaults/main.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -cmk_site_url: "http://192.168.56.1/mysite" -cmk_site_user: automation -cmk_site_password: myautomationpassword -cmk_site_default_folder: "ansible" diff --git a/roles/host_registration/handlers/main.yml b/roles/host_registration/handlers/main.yml deleted file mode 100644 index 6b4a298a7..000000000 --- a/roles/host_registration/handlers/main.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- - -- name: activate changes - checkmk_changes: - url: "{{ cmk_site_url }}" - user: "{{ cmk_site_user }}" - password: "{{ cmk_site_password }}" - allow_foreign_changes: yes - comments: 'Changes made by Ansible' - delegate_to: localhost diff --git a/roles/host_registration/meta/main.yml b/roles/host_registration/meta/main.yml deleted file mode 100644 index 0aa3631ce..000000000 --- a/roles/host_registration/meta/main.yml +++ /dev/null @@ -1,9 +0,0 @@ -galaxy_info: - role_name: cmk_host_registration - author: MArcel Arentz - description: Register Host at checkMK site, discover services and activate these changes - company: tribe29 GmbH - - license: GPLv2 - - min_ansible_version: 2.4 diff --git a/roles/host_registration/tasks/main.yml b/roles/host_registration/tasks/main.yml deleted file mode 100644 index 0289561c8..000000000 --- a/roles/host_registration/tasks/main.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- - -- set_fact: - OS: "linux" - when: ansible_system == "Linux" - -- set_fact: - OS: "windows" - when: ansible_os_family == "Windows" - -- name: Add host - checkmk_host: - url: "{{ cmk_site_url }}" - user: "{{ cmk_site_user }}" - password: "{{ cmk_site_password }}" - name: "{{ ansible_fqdn }}" - folder: "{{ cmk_site_default_folder }}/{{ OS }}" - state: present - discover_services: yes - delegate_to: localhost - notify: - - activate changes From df067b05e66ddc0d0b45e013c40078aeccd9eabd Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 29 Mar 2022 15:57:27 +0200 Subject: [PATCH 02/18] Add Vagrantfile. --- .gitignore | 1 + Vagrantfile | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 Vagrantfile diff --git a/.gitignore b/.gitignore index a83b4e74c..de7a6920e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .*.swp .*.swo *~ +.vagrant/ tests/output playbooks/vars/config.yml playbooks/test.yml \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 000000000..77db53a15 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,66 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. + +Vagrant.configure("2") do |config| + + # Ubuntu + config.vm.define "ansibuntu", primary: true do |srv| + srv.vm.box = "ubuntu/focal64" + srv.vm.network "private_network", ip: "192.168.56.61" + srv.ssh.insert_key = false + srv.vm.provider "virtualbox" do |v| + v.name = 'ansibuntu' + v.memory = 1024 + v.cpus = 2 + end + srv.vm.provision "shell", + inline: "apt-get -y update --quiet && apt-get -y install vim htop curl wget git" + end + + # Debian + config.vm.define "debsible", primary: true do |srv| + srv.vm.box = "debian/bullseye64" + srv.vm.network "private_network", ip: "192.168.56.62" + srv.ssh.insert_key = false + srv.vm.provider "virtualbox" do |v| + v.name = 'debsible' + v.memory = 1024 + v.cpus = 2 + end + srv.vm.provision "shell", + inline: "apt-get -y update --quiet && apt-get -y install vim htop curl wget git" + end + + # CentOS Stream + config.vm.define "anstream", primary: true do |srv| + srv.vm.box = "centos/stream8" + srv.vm.network "private_network", ip: "192.168.56.63" + srv.ssh.insert_key = false + srv.vm.provider "virtualbox" do |v| + v.name = 'anstream' + v.memory = 1024 + v.cpus = 2 + end + srv.vm.provision "shell", + inline: "dnf --quiet check-update ; dnf -y install vim curl wget git" + end + + # openSUSE Tumbleweed + config.vm.define "ansuse", primary: true do |srv| + srv.vm.box = "opensuse/Tumbleweed.x86_64" + srv.vm.network "private_network", ip: "192.168.56.64" + srv.ssh.insert_key = false + srv.vm.provider "virtualbox" do |v| + v.name = 'ansuse' + v.memory = 1024 + v.cpus = 2 + end + srv.vm.provision "shell", + inline: "zypper --quiet patch-check" + end +end From a393efc90c0fb65650c5ea4fd4f8e1e66cf80e44 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 29 Mar 2022 15:59:26 +0200 Subject: [PATCH 03/18] Add agent role. --- roles/agent/defaults/main.yml | 7 +++++++ roles/agent/tasks/Debian.yml | 14 ++++++++++++++ roles/agent/tasks/RedHat.yml | 16 ++++++++++++++++ roles/agent/tasks/Suse.yml | 16 ++++++++++++++++ roles/agent/tasks/main.yml | 19 +++++++++++++++++++ roles/agent/vars/Debian.yml | 10 ++++++++++ roles/agent/vars/RedHat.yml | 10 ++++++++++ roles/agent/vars/Suse.yml | 10 ++++++++++ 8 files changed, 102 insertions(+) create mode 100644 roles/agent/defaults/main.yml create mode 100644 roles/agent/tasks/Debian.yml create mode 100644 roles/agent/tasks/RedHat.yml create mode 100644 roles/agent/tasks/Suse.yml create mode 100644 roles/agent/tasks/main.yml create mode 100644 roles/agent/vars/Debian.yml create mode 100644 roles/agent/vars/RedHat.yml create mode 100644 roles/agent/vars/Suse.yml diff --git a/roles/agent/defaults/main.yml b/roles/agent/defaults/main.yml new file mode 100644 index 000000000..cc1ee4029 --- /dev/null +++ b/roles/agent/defaults/main.yml @@ -0,0 +1,7 @@ +--- +checkmk_version: "2.0.0p20" +checkmk_edition: cre +checkmk_protocol: http +checkmk_server: localhost +checkmk_site: my_site +checkmk_site_url: "{{ checkmk_protocol }}://{{ checkmk_server }}/{{ checkmk_site }}" diff --git a/roles/agent/tasks/Debian.yml b/roles/agent/tasks/Debian.yml new file mode 100644 index 000000000..19e5f132d --- /dev/null +++ b/roles/agent/tasks/Debian.yml @@ -0,0 +1,14 @@ +--- +- name: "Install Checkmk CRE Agent on Debian Derivates." + become: 'yes' + apt: + deb: "{{ checkmk_agent.file.cre }}" + state: present + when: checkmk_edition == "cre" + +- name: "Install Checkmk CEE Agent on Debian Derivates." + become: 'yes' + apt: + deb: "{{ checkmk_agent.file.cee }}" + state: present + when: checkmk_edition == "cee" diff --git a/roles/agent/tasks/RedHat.yml b/roles/agent/tasks/RedHat.yml new file mode 100644 index 000000000..21276c983 --- /dev/null +++ b/roles/agent/tasks/RedHat.yml @@ -0,0 +1,16 @@ +--- +- name: "Install Checkmk CRE Agent on RedHat Derivates." + become: 'yes' + yum: + name: "{{ checkmk_agent.file.cre }}" + state: present + disable_gpg_check: yes + when: checkmk_edition == "cre" + +- name: "Install Checkmk CEE Agent on RedHat Derivates." + become: 'yes' + yum: + name: "{{ checkmk_agent.file.cee }}" + state: present + disable_gpg_check: yes + when: checkmk_edition == "cee" diff --git a/roles/agent/tasks/Suse.yml b/roles/agent/tasks/Suse.yml new file mode 100644 index 000000000..709be6429 --- /dev/null +++ b/roles/agent/tasks/Suse.yml @@ -0,0 +1,16 @@ +--- +- name: "Install Checkmk CRE Agent on Suse Derivates." + become: 'yes' + zypper: + name: "{{ checkmk_agent.file.cre }}" + state: present + disable_gpg_check: yes + when: checkmk_edition == "cre" + +- name: "Install Checkmk CEE Agent on Suse Derivates." + become: 'yes' + zypper: + name: "{{ checkmk_agent.file.cee }}" + state: present + disable_gpg_check: yes + when: checkmk_edition == "cee" diff --git a/roles/agent/tasks/main.yml b/roles/agent/tasks/main.yml new file mode 100644 index 000000000..a3fcf64ef --- /dev/null +++ b/roles/agent/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- name: "Include Derivate specific Variables." + include_vars: "{{ ansible_os_family }}.yml" + +- name: "Download Checkmk CRE Agent." + get_url: + url: "{{ checkmk_agent.url.cre }}" + dest: "{{ checkmk_agent.file.cre }}" + when: checkmk_edition == "cre" + +# Not implemented yet, need API +- name: "Download Checkmk CEE Agent." + get_url: + url: "{{ checkmk_agent.url.cee }}" + dest: "{{ checkmk_agent.file.cre }}" + when: checkmk_edition == "cee" + +- name: "Run OS Family specific Tasks." + include_tasks: "{{ ansible_os_family }}.yml" diff --git a/roles/agent/vars/Debian.yml b/roles/agent/vars/Debian.yml new file mode 100644 index 000000000..5dc48245e --- /dev/null +++ b/roles/agent/vars/Debian.yml @@ -0,0 +1,10 @@ +--- +checkmk_host_tmp_dir: "/tmp" + +checkmk_agent: + url: + cre: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent_{{ checkmk_version }}-1_all.deb" + cee: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent_{{ checkmk_version }}-1_all.deb" + file: + cre: "{{ checkmk_host_tmp_dir }}/check-mk-agent_{{ checkmk_version }}.deb" + cee: "{{ checkmk_host_tmp_dir }}/check-mk-agent_{{ checkmk_version }}.deb" diff --git a/roles/agent/vars/RedHat.yml b/roles/agent/vars/RedHat.yml new file mode 100644 index 000000000..ebdc1a0e1 --- /dev/null +++ b/roles/agent/vars/RedHat.yml @@ -0,0 +1,10 @@ +--- +checkmk_host_tmp_dir: "/tmp" + +checkmk_agent: + url: + cre: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + cee: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + file: + cre: "{{ checkmk_host_tmp_dir }}/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + cee: "{{ checkmk_host_tmp_dir }}/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" diff --git a/roles/agent/vars/Suse.yml b/roles/agent/vars/Suse.yml new file mode 100644 index 000000000..4cb287133 --- /dev/null +++ b/roles/agent/vars/Suse.yml @@ -0,0 +1,10 @@ +--- +checkmk_host_tmp_dir: "/tmp" + +checkmk_agent: + url: + cre: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + cee: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + file: + cre: "{{ checkmk_host_tmp_dir }}/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + cee: "{{ checkmk_host_tmp_dir }}/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" From 4c25dfc5d40d1e8c105a1d606746446931dc6fc4 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 29 Mar 2022 15:59:34 +0200 Subject: [PATCH 04/18] Add playbook to run roles. --- playbooks/roles.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 playbooks/roles.yml diff --git a/playbooks/roles.yml b/playbooks/roles.yml new file mode 100644 index 000000000..412a2b646 --- /dev/null +++ b/playbooks/roles.yml @@ -0,0 +1,6 @@ +- name: "Run all roles." + hosts: vagrant + tasks: + - name: "Run agent role." + ansible.builtin.include_role: + name: agent From a1497267fcae569d7c355855ad21e5d36657d051 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 29 Mar 2022 16:00:08 +0200 Subject: [PATCH 05/18] Add integration test for agent role. --- .../targets/role_agent/tasks/main.yml | 10 +++++++ .../targets/role_agent/tasks/prep.yml | 18 ++++++++++++ .../targets/role_agent/tasks/test.yml | 4 +++ .../targets/role_agent/vars/main.yml | 28 +++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 tests/integration/targets/role_agent/tasks/main.yml create mode 100644 tests/integration/targets/role_agent/tasks/prep.yml create mode 100644 tests/integration/targets/role_agent/tasks/test.yml create mode 100644 tests/integration/targets/role_agent/vars/main.yml diff --git a/tests/integration/targets/role_agent/tasks/main.yml b/tests/integration/targets/role_agent/tasks/main.yml new file mode 100644 index 000000000..22c526e43 --- /dev/null +++ b/tests/integration/targets/role_agent/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: "Run preparations." + ansible.builtin.import_tasks: prep.yml + +- name: "Wait for site to be ready." + ansible.builtin.pause: + seconds: 5 + +- name: "Run tests." + ansible.builtin.import_tasks: test.yml diff --git a/tests/integration/targets/role_agent/tasks/prep.yml b/tests/integration/targets/role_agent/tasks/prep.yml new file mode 100644 index 000000000..3029a5d2a --- /dev/null +++ b/tests/integration/targets/role_agent/tasks/prep.yml @@ -0,0 +1,18 @@ +--- +- name: "Download Checkmk." + ansible.builtin.get_url: + url: "{{ download_url }}" + dest: /tmp/checkmk-server.deb + +- name: "Install Checkmk." + ansible.builtin.apt: + deb: /tmp/checkmk-server.deb + state: present + +- name: "Create site." + ansible.builtin.command: "omd create --no-tmpfs --admin-password {{ automation_secret }} {{ site }}" + args: + creates: "/omd/sites/{{ site }}" + +- name: "Start site." + ansible.builtin.shell: "omd status -b {{ site }} || omd start {{ site }}" diff --git a/tests/integration/targets/role_agent/tasks/test.yml b/tests/integration/targets/role_agent/tasks/test.yml new file mode 100644 index 000000000..ed3c18bb9 --- /dev/null +++ b/tests/integration/targets/role_agent/tasks/test.yml @@ -0,0 +1,4 @@ +--- +- name: "Run role." + ansible.builtin.include_role: + name: agent diff --git a/tests/integration/targets/role_agent/vars/main.yml b/tests/integration/targets/role_agent/vars/main.yml new file mode 100644 index 000000000..6eab98652 --- /dev/null +++ b/tests/integration/targets/role_agent/vars/main.yml @@ -0,0 +1,28 @@ +--- +download_url: "https://download.checkmk.com/checkmk/2.0.0p20/check-mk-raw-2.0.0p20_0.bionic_amd64.deb" +site: "test" +server_url: "http://127.0.0.1/" +automation_user: "cmkadmin" +automation_secret: "d7589df1-01db-4eda-9858-dbcff8d0c361" + +checkmk_hosts: + - name: test1.tld + folder: "/" + - name: test2.tld + folder: "/" + - name: test3.tld + folder: "/" + - name: test4.tld + folder: "/" + - name: test5.tld + folder: "/" + - name: test6.tld + folder: "/" + - name: test7.tld + folder: "/" + - name: test8.tld + folder: "/" + - name: test9.tld + folder: "/" + - name: test10.tld + folder: "/" From 7e953eed064d8b051f0125ac949ad730df8d0d2f Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 31 Mar 2022 13:38:49 +0200 Subject: [PATCH 06/18] Add notes to agent role main.yml. --- roles/agent/tasks/main.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/roles/agent/tasks/main.yml b/roles/agent/tasks/main.yml index a3fcf64ef..c787eba72 100644 --- a/roles/agent/tasks/main.yml +++ b/roles/agent/tasks/main.yml @@ -8,7 +8,12 @@ dest: "{{ checkmk_agent.file.cre }}" when: checkmk_edition == "cre" -# Not implemented yet, need API +# Not implemented yet, needs API +# https://docs.checkmk.com/master/de/agent_linux.html +# root@linux# curl -OJG "mycmkserver/mysite/check_mk/api/1.0/domain-types/agent/actions/download/invoke"; \ +# --header 'Accept: application/octet-stream' \ +# --header 'Authorization: Bearer automation myautomationsecret' \ +# --data-urlencode 'os_type=linux_deb' - name: "Download Checkmk CEE Agent." get_url: url: "{{ checkmk_agent.url.cee }}" From 64901d0e2fb062059f99ab1b7878ec134c8a57b5 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Mon, 16 May 2022 11:10:23 +0200 Subject: [PATCH 07/18] Add boxes for role testing and fix demo.yml. --- Vagrantfile | 64 ++++++++++++++++++++++++++++++++++++++++++---- playbooks/demo.yml | 2 +- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index bfccaac09..86010e19d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,7 +10,7 @@ Vagrant.configure("2") do |config| # Ubuntu config.vm.define "ansible-collection", primary: true do |srv| srv.vm.box = "ubuntu/focal64" - srv.vm.network "private_network", ip: "IP_ADDRESS" + srv.vm.network "private_network", ip: "192.168.56.42" srv.ssh.insert_key = false srv.vm.provider "virtualbox" do |v| v.name = 'ansible-collection' @@ -23,7 +23,7 @@ Vagrant.configure("2") do |config| pip install -r /vagrant/requirements.txt ansible-galaxy collection install -f -r /vagrant/requirements.yml wget "https://download.checkmk.com/checkmk/2.0.0p23/check-mk-raw-2.0.0p23_0.focal_amd64.deb" -O /tmp/checkmk-stable.deb - wget "https://download.checkmk.com/checkmk/2.1.0b5/check-mk-raw-2.1.0b5_0.focal_amd64.deb" -O /tmp/checkmk-beta.deb + wget "https://download.checkmk.com/checkmk/2.1.0b8/check-mk-raw-2.1.0b5_0.focal_amd64.deb" -O /tmp/checkmk-beta.deb apt-get install -y /tmp/checkmk-stable.deb omd create --admin-password 'cmk' stable apt-get install -y /tmp/checkmk-beta.deb @@ -32,8 +32,62 @@ Vagrant.configure("2") do |config| omd status -b beta || omd start beta SCRIPT srv.vm.provision "shell", inline: $script - # srv.vm.provision "shell" do |s| - # s.path = "./setup.sh" - # end end + + # Ubuntu + config.vm.define "ansibuntu", autostart: false , primary: false do |srv| + srv.vm.box = "ubuntu/focal64" + srv.vm.network "private_network", ip: "192.168.56.61" + srv.ssh.insert_key = false + srv.vm.provider "virtualbox" do |v| + v.name = 'ansibuntu' + v.memory = 1024 + v.cpus = 2 + end + srv.vm.provision "shell", + inline: "apt-get -y update --quiet && apt-get -y install vim htop curl wget git" + end + + # Debian + config.vm.define "debsible", autostart: false , primary: false do |srv| + srv.vm.box = "debian/bullseye64" + srv.vm.network "private_network", ip: "192.168.56.62" + srv.ssh.insert_key = false + srv.vm.provider "virtualbox" do |v| + v.name = 'debsible' + v.memory = 1024 + v.cpus = 2 + end + srv.vm.provision "shell", + inline: "apt-get -y update --quiet && apt-get -y install vim htop curl wget git" + end + + # CentOS Stream + config.vm.define "anstream", autostart: false , primary: false do |srv| + srv.vm.box = "centos/stream8" + srv.vm.network "private_network", ip: "192.168.56.63" + srv.ssh.insert_key = false + srv.vm.provider "virtualbox" do |v| + v.name = 'anstream' + v.memory = 1024 + v.cpus = 2 + end + srv.vm.provision "shell", + inline: "dnf --quiet check-update ; dnf -y install vim curl wget git" + end + + # openSUSE + config.vm.define "ansuse", autostart: false , primary: false do |srv| + srv.vm.box = "opensuse/Tumbleweed.x86_64" + srv.vm.network "private_network", ip: "192.168.56.64" + srv.ssh.insert_key = false + srv.vm.provider "virtualbox" do |v| + v.name = 'ansuse' + v.memory = 1024 + v.cpus = 2 + end + srv.vm.provision "shell", + inline: "zypper --quiet up -y" +end + end diff --git a/playbooks/demo.yml b/playbooks/demo.yml index d8afd4242..7819b0dc5 100644 --- a/playbooks/demo.yml +++ b/playbooks/demo.yml @@ -1,5 +1,5 @@ - name: "Test all modules." - hosts: all + hosts: test gather_facts: 'no' vars_files: - ./vars/config.yml From 47128f91e94d106792811d9ade6be142681854f1 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Mon, 16 May 2022 11:41:14 +0200 Subject: [PATCH 08/18] Update roles.yml. --- playbooks/roles.yml | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/playbooks/roles.yml b/playbooks/roles.yml index 412a2b646..5c6fd6236 100644 --- a/playbooks/roles.yml +++ b/playbooks/roles.yml @@ -1,6 +1,41 @@ - name: "Run all roles." hosts: vagrant + vars_files: + - ./vars/config.yml + roles: + # - tribe29.checkmk.agent + - agent tasks: - - name: "Run agent role." - ansible.builtin.include_role: - name: agent + - name: "Create host." + host: + server_url: "{{ server_url }}" + site: "{{ site }}" + automation_user: "{{ automation_user }}" + automation_secret: "{{ automation_secret }}" + host_name: "{{ inventory_hostname }}" + folder: "{{ checkmk_folder_path }}" + attributes: + site: "{{ site }}" + ipaddress: "{{ ansible_host }}" + state: "present" + delegate_to: localhost + - name: "Discover services on host." + discovery: + server_url: "{{ server_url }}" + site: "{{ site }}" + automation_user: "{{ automation_user }}" + automation_secret: "{{ automation_secret }}" + host_name: "{{ inventory_hostname }}" + state: "fix_all" + delegate_to: localhost + - name: "Activate changes." + activation: + server_url: "{{ server_url }}" + site: "{{ site }}" + automation_user: "{{ automation_user }}" + automation_secret: "{{ automation_secret }}" + force_foreign_changes: 'true' + sites: + - "{{ site }}" + delegate_to: localhost + run_once: 'true' From 88130295cdcdf0758e687e65ad8d0eed8e27b939 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Mon, 16 May 2022 11:41:41 +0200 Subject: [PATCH 09/18] Update defaults. --- roles/agent/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/agent/defaults/main.yml b/roles/agent/defaults/main.yml index cc1ee4029..c32842b24 100644 --- a/roles/agent/defaults/main.yml +++ b/roles/agent/defaults/main.yml @@ -1,5 +1,5 @@ --- -checkmk_version: "2.0.0p20" +checkmk_version: "2.0.0p23" checkmk_edition: cre checkmk_protocol: http checkmk_server: localhost From 55f8a8c5f1f4beeeb4046c20b7e870ef60746fea Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 17 May 2022 09:11:19 +0200 Subject: [PATCH 10/18] Minor clean up. --- playbooks/roles.yml | 71 +++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/playbooks/roles.yml b/playbooks/roles.yml index 5c6fd6236..0d18288ea 100644 --- a/playbooks/roles.yml +++ b/playbooks/roles.yml @@ -2,40 +2,41 @@ hosts: vagrant vars_files: - ./vars/config.yml + roles: - # - tribe29.checkmk.agent - agent - tasks: - - name: "Create host." - host: - server_url: "{{ server_url }}" - site: "{{ site }}" - automation_user: "{{ automation_user }}" - automation_secret: "{{ automation_secret }}" - host_name: "{{ inventory_hostname }}" - folder: "{{ checkmk_folder_path }}" - attributes: - site: "{{ site }}" - ipaddress: "{{ ansible_host }}" - state: "present" - delegate_to: localhost - - name: "Discover services on host." - discovery: - server_url: "{{ server_url }}" - site: "{{ site }}" - automation_user: "{{ automation_user }}" - automation_secret: "{{ automation_secret }}" - host_name: "{{ inventory_hostname }}" - state: "fix_all" - delegate_to: localhost - - name: "Activate changes." - activation: - server_url: "{{ server_url }}" - site: "{{ site }}" - automation_user: "{{ automation_user }}" - automation_secret: "{{ automation_secret }}" - force_foreign_changes: 'true' - sites: - - "{{ site }}" - delegate_to: localhost - run_once: 'true' + + # tasks: + # - name: "Create host." + # host: + # server_url: "{{ server_url }}" + # site: "{{ site }}" + # automation_user: "{{ automation_user }}" + # automation_secret: "{{ automation_secret }}" + # host_name: "{{ inventory_hostname }}" + # folder: "{{ checkmk_folder_path }}" + # attributes: + # site: "{{ site }}" + # ipaddress: "{{ ansible_host }}" + # state: "present" + # delegate_to: localhost + # - name: "Discover services on host." + # discovery: + # server_url: "{{ server_url }}" + # site: "{{ site }}" + # automation_user: "{{ automation_user }}" + # automation_secret: "{{ automation_secret }}" + # host_name: "{{ inventory_hostname }}" + # state: "fix_all" + # delegate_to: localhost + # - name: "Activate changes." + # activation: + # server_url: "{{ server_url }}" + # site: "{{ site }}" + # automation_user: "{{ automation_user }}" + # automation_secret: "{{ automation_secret }}" + # force_foreign_changes: 'true' + # sites: + # - "{{ site }}" + # delegate_to: localhost + # run_once: 'true' From bcb93284e9b42d89a5bb7ec8d141b3a143d28e2c Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 17 May 2022 10:19:36 +0200 Subject: [PATCH 11/18] Prepare agent role for initial release. --- roles/agent/.yamllint | 33 ++++++++++++++++++ roles/agent/README.md | 64 +++++++++++++++++++++++++++++++++++ roles/agent/defaults/main.yml | 3 +- roles/agent/meta/main.yml | 60 ++++++++++++++++++++++++++++++++ roles/agent/tasks/Debian.yml | 9 +---- roles/agent/tasks/RedHat.yml | 10 +----- roles/agent/tasks/Suse.yml | 10 +----- roles/agent/tasks/main.yml | 18 ++-------- roles/agent/vars/main.yml | 2 ++ 9 files changed, 166 insertions(+), 43 deletions(-) create mode 100644 roles/agent/.yamllint create mode 100644 roles/agent/README.md create mode 100644 roles/agent/meta/main.yml create mode 100644 roles/agent/vars/main.yml diff --git a/roles/agent/.yamllint b/roles/agent/.yamllint new file mode 100644 index 000000000..882767605 --- /dev/null +++ b/roles/agent/.yamllint @@ -0,0 +1,33 @@ +--- +# Based on ansible-lint config +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: disable + key-duplicates: enable + line-length: disable + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable + truthy: disable diff --git a/roles/agent/README.md b/roles/agent/README.md new file mode 100644 index 000000000..1e920036c --- /dev/null +++ b/roles/agent/README.md @@ -0,0 +1,64 @@ +# tribe29.checkmk.agent + + +This role installs Checkmk agents. + +## Requirements + + +None. + +## Role Variables + + + + checkmk_version: "2.0.0p24" + +The Checkmk version of your site. + + checkmk_edition: cre + +The edition you are using. Valid values are `cre` and `cee`. +Note, that `cee` is not implemented yet. + + checkmk_protocol: http + +The protocol used to connect to your Checkmk site. + + checkmk_server: localhost + +The FQDN or IP address of your Checkmk server. + + checkmk_site: my_site + +The name of your Checkmk site. + +## Dependencies + + +None. + +## Example Playbook + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: all + roles: + - tribe29.checkmk.agent + +## Contributing + +See [CONTRIBUTING](../../CONTRIBUTING). + +## Disclaimer + +This role is provided AS IS and we can and will not guarantee that the role works as intended, nor can we be accountable for any damage or misconfiguration done by this role. Study the role thoroughly before using it. + +## License + +See [LICENSE](../../LICENSE). + +## Author Information + + +Robin Gierse (@robin-tribe29) diff --git a/roles/agent/defaults/main.yml b/roles/agent/defaults/main.yml index c32842b24..0fac41a08 100644 --- a/roles/agent/defaults/main.yml +++ b/roles/agent/defaults/main.yml @@ -1,7 +1,6 @@ --- -checkmk_version: "2.0.0p23" +checkmk_version: "2.0.0p24" checkmk_edition: cre checkmk_protocol: http checkmk_server: localhost checkmk_site: my_site -checkmk_site_url: "{{ checkmk_protocol }}://{{ checkmk_server }}/{{ checkmk_site }}" diff --git a/roles/agent/meta/main.yml b/roles/agent/meta/main.yml new file mode 100644 index 000000000..b5db92da6 --- /dev/null +++ b/roles/agent/meta/main.yml @@ -0,0 +1,60 @@ +galaxy_info: + role_name: tribe29.checkmk.agent + + author: Robin Gierse + company: tribe29 GmbH + description: This role installs Checkmk agents. + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: GPL-2.0-or-later + + min_ansible_version: 2.4 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: Debian + versions: + - all + - name: Ubuntu + versions: + - all + - name: EL + versions: + - all + - name: opensuse + versions: + - all + - name: SLES + versions: + - all + + galaxy_tags: [tribe29, checkmk, monitoring, agent] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + \ No newline at end of file diff --git a/roles/agent/tasks/Debian.yml b/roles/agent/tasks/Debian.yml index 19e5f132d..2d5964c8e 100644 --- a/roles/agent/tasks/Debian.yml +++ b/roles/agent/tasks/Debian.yml @@ -1,14 +1,7 @@ --- - name: "Install Checkmk CRE Agent on Debian Derivates." become: 'yes' - apt: + ansible.builtin.apt: deb: "{{ checkmk_agent.file.cre }}" state: present when: checkmk_edition == "cre" - -- name: "Install Checkmk CEE Agent on Debian Derivates." - become: 'yes' - apt: - deb: "{{ checkmk_agent.file.cee }}" - state: present - when: checkmk_edition == "cee" diff --git a/roles/agent/tasks/RedHat.yml b/roles/agent/tasks/RedHat.yml index 21276c983..dcf87a970 100644 --- a/roles/agent/tasks/RedHat.yml +++ b/roles/agent/tasks/RedHat.yml @@ -1,16 +1,8 @@ --- - name: "Install Checkmk CRE Agent on RedHat Derivates." become: 'yes' - yum: + ansible.builtin.yum: name: "{{ checkmk_agent.file.cre }}" state: present disable_gpg_check: yes when: checkmk_edition == "cre" - -- name: "Install Checkmk CEE Agent on RedHat Derivates." - become: 'yes' - yum: - name: "{{ checkmk_agent.file.cee }}" - state: present - disable_gpg_check: yes - when: checkmk_edition == "cee" diff --git a/roles/agent/tasks/Suse.yml b/roles/agent/tasks/Suse.yml index 709be6429..78e0f15be 100644 --- a/roles/agent/tasks/Suse.yml +++ b/roles/agent/tasks/Suse.yml @@ -1,16 +1,8 @@ --- - name: "Install Checkmk CRE Agent on Suse Derivates." become: 'yes' - zypper: + ansible.builtin.zypper: name: "{{ checkmk_agent.file.cre }}" state: present disable_gpg_check: yes when: checkmk_edition == "cre" - -- name: "Install Checkmk CEE Agent on Suse Derivates." - become: 'yes' - zypper: - name: "{{ checkmk_agent.file.cee }}" - state: present - disable_gpg_check: yes - when: checkmk_edition == "cee" diff --git a/roles/agent/tasks/main.yml b/roles/agent/tasks/main.yml index c787eba72..82ce17d1e 100644 --- a/roles/agent/tasks/main.yml +++ b/roles/agent/tasks/main.yml @@ -1,24 +1,12 @@ --- - name: "Include Derivate specific Variables." - include_vars: "{{ ansible_os_family }}.yml" + ansible.builtin.include_vars: "{{ ansible_os_family }}.yml" - name: "Download Checkmk CRE Agent." - get_url: + ansible.builtin.get_url: url: "{{ checkmk_agent.url.cre }}" dest: "{{ checkmk_agent.file.cre }}" when: checkmk_edition == "cre" -# Not implemented yet, needs API -# https://docs.checkmk.com/master/de/agent_linux.html -# root@linux# curl -OJG "mycmkserver/mysite/check_mk/api/1.0/domain-types/agent/actions/download/invoke"; \ -# --header 'Accept: application/octet-stream' \ -# --header 'Authorization: Bearer automation myautomationsecret' \ -# --data-urlencode 'os_type=linux_deb' -- name: "Download Checkmk CEE Agent." - get_url: - url: "{{ checkmk_agent.url.cee }}" - dest: "{{ checkmk_agent.file.cre }}" - when: checkmk_edition == "cee" - - name: "Run OS Family specific Tasks." - include_tasks: "{{ ansible_os_family }}.yml" + ansible.builtin.include_tasks: "{{ ansible_os_family }}.yml" diff --git a/roles/agent/vars/main.yml b/roles/agent/vars/main.yml new file mode 100644 index 000000000..fc01d0124 --- /dev/null +++ b/roles/agent/vars/main.yml @@ -0,0 +1,2 @@ +--- +checkmk_site_url: "{{ checkmk_protocol }}://{{ checkmk_server }}/{{ checkmk_site }}" From 464c077ff6cfda877278f2fc8c15dc73b6ac7f4e Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 17 May 2022 10:23:33 +0200 Subject: [PATCH 12/18] Add changelog. --- changelogs/fragments/role-agent.yml | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 changelogs/fragments/role-agent.yml diff --git a/changelogs/fragments/role-agent.yml b/changelogs/fragments/role-agent.yml new file mode 100644 index 000000000..1618347c5 --- /dev/null +++ b/changelogs/fragments/role-agent.yml @@ -0,0 +1,47 @@ +# https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs-how-to +minor_changes: + - Add agent role. Currently supports the vanilla agent. + +# known_issues: +# - This release is still in development and a heavy work in progress. +# - Discovery module is not feature complete yet. +# - Downtime module is not fully idempotent yet. This affects service downtimes and deletions. + +## Line Format +# When writing a changelog entry, use the following format: + +# - scope - description starting with a lowercase letter and ending with a period at the very end. Multiple sentences are allowed (https://github.com/reference/to/an/issue or, if there is no issue, reference to a pull request itself). + +# The scope is usually a module or plugin name or group of modules or plugins, for example, lookup plugins. While module names can (and should) be mentioned directly (foo_module), plugin names should always be followed by the type (foo inventory plugin). + +# For changes that are not really scoped (for example, which affect a whole collection), use the following format: + +# - Description starting with an uppercase letter and ending with a dot at the very end. Multiple sentences are allowed (https://github.com/reference/to/an/issue or, if there is no issue, reference to a pull request itself). + + +## Possible keys: + +# breaking_changes + +# Changes that break existing playbooks or roles. This includes any change to existing behavior that forces users to update tasks. Displayed in both the changelogs and the Porting Guides. +# major_changes + +# Major changes to Ansible itself. Generally does not include module or plugin changes. Displayed in both the changelogs and the Porting Guides. +# minor_changes + +# Minor changes to Ansible, modules, or plugins. This includes new features, new parameters added to modules, or behavior changes to existing parameters. +# deprecated_features + +# Features that have been deprecated and are scheduled for removal in a future release. Displayed in both the changelogs and the Porting Guides. +# removed_features + +# Features that were previously deprecated and are now removed. Displayed in both the changelogs and the Porting Guides. +# security_fixes + +# Fixes that address CVEs or resolve security concerns. Include links to CVE information. +# bugfixes + +# Fixes that resolve issues. +# known_issues + +# Known issues that are currently not fixed or will not be fixed. From 3d7fe748031e5d1079b5ebe53cb62b0527eb6a6f Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 17 May 2022 10:36:55 +0200 Subject: [PATCH 13/18] Exclude roles from integration tests for now. --- .../workflows/ansible-integration-tests.yaml | 1 + .../targets/role_agent/tasks/main.yml | 10 ------- .../targets/role_agent/tasks/prep.yml | 18 ------------ .../targets/role_agent/tasks/test.yml | 4 --- .../targets/role_agent/vars/main.yml | 28 ------------------- 5 files changed, 1 insertion(+), 60 deletions(-) delete mode 100644 tests/integration/targets/role_agent/tasks/main.yml delete mode 100644 tests/integration/targets/role_agent/tasks/prep.yml delete mode 100644 tests/integration/targets/role_agent/tasks/test.yml delete mode 100644 tests/integration/targets/role_agent/vars/main.yml diff --git a/.github/workflows/ansible-integration-tests.yaml b/.github/workflows/ansible-integration-tests.yaml index bb72e374d..0d6b0ff05 100644 --- a/.github/workflows/ansible-integration-tests.yaml +++ b/.github/workflows/ansible-integration-tests.yaml @@ -18,6 +18,7 @@ on: - 'changelogs/**' - '**.md' - '**.rst' + - 'roles/**' env: NAMESPACE: tribe29 diff --git a/tests/integration/targets/role_agent/tasks/main.yml b/tests/integration/targets/role_agent/tasks/main.yml deleted file mode 100644 index 22c526e43..000000000 --- a/tests/integration/targets/role_agent/tasks/main.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: "Run preparations." - ansible.builtin.import_tasks: prep.yml - -- name: "Wait for site to be ready." - ansible.builtin.pause: - seconds: 5 - -- name: "Run tests." - ansible.builtin.import_tasks: test.yml diff --git a/tests/integration/targets/role_agent/tasks/prep.yml b/tests/integration/targets/role_agent/tasks/prep.yml deleted file mode 100644 index 3029a5d2a..000000000 --- a/tests/integration/targets/role_agent/tasks/prep.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: "Download Checkmk." - ansible.builtin.get_url: - url: "{{ download_url }}" - dest: /tmp/checkmk-server.deb - -- name: "Install Checkmk." - ansible.builtin.apt: - deb: /tmp/checkmk-server.deb - state: present - -- name: "Create site." - ansible.builtin.command: "omd create --no-tmpfs --admin-password {{ automation_secret }} {{ site }}" - args: - creates: "/omd/sites/{{ site }}" - -- name: "Start site." - ansible.builtin.shell: "omd status -b {{ site }} || omd start {{ site }}" diff --git a/tests/integration/targets/role_agent/tasks/test.yml b/tests/integration/targets/role_agent/tasks/test.yml deleted file mode 100644 index ed3c18bb9..000000000 --- a/tests/integration/targets/role_agent/tasks/test.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- name: "Run role." - ansible.builtin.include_role: - name: agent diff --git a/tests/integration/targets/role_agent/vars/main.yml b/tests/integration/targets/role_agent/vars/main.yml deleted file mode 100644 index 6eab98652..000000000 --- a/tests/integration/targets/role_agent/vars/main.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -download_url: "https://download.checkmk.com/checkmk/2.0.0p20/check-mk-raw-2.0.0p20_0.bionic_amd64.deb" -site: "test" -server_url: "http://127.0.0.1/" -automation_user: "cmkadmin" -automation_secret: "d7589df1-01db-4eda-9858-dbcff8d0c361" - -checkmk_hosts: - - name: test1.tld - folder: "/" - - name: test2.tld - folder: "/" - - name: test3.tld - folder: "/" - - name: test4.tld - folder: "/" - - name: test5.tld - folder: "/" - - name: test6.tld - folder: "/" - - name: test7.tld - folder: "/" - - name: test8.tld - folder: "/" - - name: test9.tld - folder: "/" - - name: test10.tld - folder: "/" From 37f6a50eb13f28efc8b3927bef1545986abd0fcb Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 17 May 2022 16:11:41 +0200 Subject: [PATCH 14/18] Rename variables. --- roles/agent/README.md | 10 +++++----- roles/agent/defaults/main.yml | 10 +++++----- roles/agent/tasks/Debian.yml | 4 ++-- roles/agent/tasks/RedHat.yml | 4 ++-- roles/agent/tasks/Suse.yml | 4 ++-- roles/agent/tasks/main.yml | 6 +++--- roles/agent/vars/Debian.yml | 12 ++++++------ roles/agent/vars/RedHat.yml | 12 ++++++------ roles/agent/vars/Suse.yml | 12 ++++++------ roles/agent/vars/main.yml | 2 +- 10 files changed, 38 insertions(+), 38 deletions(-) diff --git a/roles/agent/README.md b/roles/agent/README.md index 1e920036c..612662b5b 100644 --- a/roles/agent/README.md +++ b/roles/agent/README.md @@ -12,24 +12,24 @@ None. - checkmk_version: "2.0.0p24" + checkmk_agent_version: "2.0.0p24" The Checkmk version of your site. - checkmk_edition: cre + checkmk_agent_edition: cre The edition you are using. Valid values are `cre` and `cee`. Note, that `cee` is not implemented yet. - checkmk_protocol: http + checkmk_agent_protocol: http The protocol used to connect to your Checkmk site. - checkmk_server: localhost + checkmk_agent_server: localhost The FQDN or IP address of your Checkmk server. - checkmk_site: my_site + checkmk_agent_site: my_site The name of your Checkmk site. diff --git a/roles/agent/defaults/main.yml b/roles/agent/defaults/main.yml index 0fac41a08..41b1bc888 100644 --- a/roles/agent/defaults/main.yml +++ b/roles/agent/defaults/main.yml @@ -1,6 +1,6 @@ --- -checkmk_version: "2.0.0p24" -checkmk_edition: cre -checkmk_protocol: http -checkmk_server: localhost -checkmk_site: my_site +checkmk_agent_version: "2.0.0p24" +checkmk_agent_edition: cre +checkmk_agent_protocol: http +checkmk_agent_server: localhost +checkmk_agent_site: my_site diff --git a/roles/agent/tasks/Debian.yml b/roles/agent/tasks/Debian.yml index 2d5964c8e..079f88328 100644 --- a/roles/agent/tasks/Debian.yml +++ b/roles/agent/tasks/Debian.yml @@ -2,6 +2,6 @@ - name: "Install Checkmk CRE Agent on Debian Derivates." become: 'yes' ansible.builtin.apt: - deb: "{{ checkmk_agent.file.cre }}" + deb: "{{ checkmk_agent_agent.file.cre }}" state: present - when: checkmk_edition == "cre" + when: checkmk_agent_edition == "cre" diff --git a/roles/agent/tasks/RedHat.yml b/roles/agent/tasks/RedHat.yml index dcf87a970..32f1abb8e 100644 --- a/roles/agent/tasks/RedHat.yml +++ b/roles/agent/tasks/RedHat.yml @@ -2,7 +2,7 @@ - name: "Install Checkmk CRE Agent on RedHat Derivates." become: 'yes' ansible.builtin.yum: - name: "{{ checkmk_agent.file.cre }}" + name: "{{ checkmk_agent_agent.file.cre }}" state: present disable_gpg_check: yes - when: checkmk_edition == "cre" + when: checkmk_agent_edition == "cre" diff --git a/roles/agent/tasks/Suse.yml b/roles/agent/tasks/Suse.yml index 78e0f15be..449cd6e22 100644 --- a/roles/agent/tasks/Suse.yml +++ b/roles/agent/tasks/Suse.yml @@ -2,7 +2,7 @@ - name: "Install Checkmk CRE Agent on Suse Derivates." become: 'yes' ansible.builtin.zypper: - name: "{{ checkmk_agent.file.cre }}" + name: "{{ checkmk_agent_agent.file.cre }}" state: present disable_gpg_check: yes - when: checkmk_edition == "cre" + when: checkmk_agent_edition == "cre" diff --git a/roles/agent/tasks/main.yml b/roles/agent/tasks/main.yml index 82ce17d1e..0b835edcf 100644 --- a/roles/agent/tasks/main.yml +++ b/roles/agent/tasks/main.yml @@ -4,9 +4,9 @@ - name: "Download Checkmk CRE Agent." ansible.builtin.get_url: - url: "{{ checkmk_agent.url.cre }}" - dest: "{{ checkmk_agent.file.cre }}" - when: checkmk_edition == "cre" + url: "{{ checkmk_agent_agent.url.cre }}" + dest: "{{ checkmk_agent_agent.file.cre }}" + when: checkmk_agent_edition == "cre" - name: "Run OS Family specific Tasks." ansible.builtin.include_tasks: "{{ ansible_os_family }}.yml" diff --git a/roles/agent/vars/Debian.yml b/roles/agent/vars/Debian.yml index 5dc48245e..9fddca0c7 100644 --- a/roles/agent/vars/Debian.yml +++ b/roles/agent/vars/Debian.yml @@ -1,10 +1,10 @@ --- -checkmk_host_tmp_dir: "/tmp" +checkmk_agent_host_tmp_dir: "/tmp" -checkmk_agent: +checkmk_agent_agent: url: - cre: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent_{{ checkmk_version }}-1_all.deb" - cee: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent_{{ checkmk_version }}-1_all.deb" + cre: "{{ checkmk_agent_site_url }}/check_mk/agents/check-mk-agent_{{ checkmk_agent_version }}-1_all.deb" + cee: "{{ checkmk_agent_site_url }}/check_mk/agents/check-mk-agent_{{ checkmk_agent_version }}-1_all.deb" file: - cre: "{{ checkmk_host_tmp_dir }}/check-mk-agent_{{ checkmk_version }}.deb" - cee: "{{ checkmk_host_tmp_dir }}/check-mk-agent_{{ checkmk_version }}.deb" + cre: "{{ checkmk_agent_host_tmp_dir }}/check-mk-agent_{{ checkmk_agent_version }}.deb" + cee: "{{ checkmk_agent_host_tmp_dir }}/check-mk-agent_{{ checkmk_agent_version }}.deb" diff --git a/roles/agent/vars/RedHat.yml b/roles/agent/vars/RedHat.yml index ebdc1a0e1..4c381ce5a 100644 --- a/roles/agent/vars/RedHat.yml +++ b/roles/agent/vars/RedHat.yml @@ -1,10 +1,10 @@ --- -checkmk_host_tmp_dir: "/tmp" +checkmk_agent_host_tmp_dir: "/tmp" -checkmk_agent: +checkmk_agent_agent: url: - cre: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" - cee: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + cre: "{{ checkmk_agent_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm" + cee: "{{ checkmk_agent_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm" file: - cre: "{{ checkmk_host_tmp_dir }}/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" - cee: "{{ checkmk_host_tmp_dir }}/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + cre: "{{ checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm" + cee: "{{ checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm" diff --git a/roles/agent/vars/Suse.yml b/roles/agent/vars/Suse.yml index 4cb287133..5ad7cd9d7 100644 --- a/roles/agent/vars/Suse.yml +++ b/roles/agent/vars/Suse.yml @@ -1,10 +1,10 @@ --- -checkmk_host_tmp_dir: "/tmp" +checkmk_agent_host_tmp_dir: "/tmp" -checkmk_agent: +checkmk_agent_agent: url: - cre: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" - cee: "{{ checkmk_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + cre: "{{ checkmk_agent_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm" + cee: "{{ checkmk_agent_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm" file: - cre: "{{ checkmk_host_tmp_dir }}/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" - cee: "{{ checkmk_host_tmp_dir }}/check-mk-agent-{{ checkmk_version }}-1.noarch.rpm" + cre: "{{ checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm" + cee: "{{ checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm" diff --git a/roles/agent/vars/main.yml b/roles/agent/vars/main.yml index fc01d0124..90d070012 100644 --- a/roles/agent/vars/main.yml +++ b/roles/agent/vars/main.yml @@ -1,2 +1,2 @@ --- -checkmk_site_url: "{{ checkmk_protocol }}://{{ checkmk_server }}/{{ checkmk_site }}" +checkmk_agent_site_url: "{{ checkmk_agent_protocol }}://{{ checkmk_agent_server }}/{{ checkmk_agent_site }}" From 901fe4dd0b00bc9749873426263b7ec88b49359d Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Mon, 23 May 2022 12:27:45 +0200 Subject: [PATCH 15/18] Test docs building. --- .github/workflows/build-docs.yaml | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/build-docs.yaml diff --git a/.github/workflows/build-docs.yaml b/.github/workflows/build-docs.yaml new file mode 100644 index 000000000..0d2a9adaa --- /dev/null +++ b/.github/workflows/build-docs.yaml @@ -0,0 +1,32 @@ +--- +name: Release Collection +on: # yamllint disable-line rule:truthy + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Get current version + id: current_version + run: echo "::set-output name=version::$(grep 'version:' galaxy.yml | cut -d ' ' -f 2)" + + - name: Set up Python. + uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Compile Collection Changelog + run: antsibull-changelog release + + - name: Compile Collection Docs + run: antsibull-docs collection --use-current --squash-hierarchy --dest-dir ./docs/ tribe29.checkmk From 9a3cfd8cb768fb3edca87d694561c2c1bd049c6a Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Mon, 23 May 2022 12:28:46 +0200 Subject: [PATCH 16/18] Fix name. --- .github/workflows/build-docs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-docs.yaml b/.github/workflows/build-docs.yaml index 0d2a9adaa..e0957925e 100644 --- a/.github/workflows/build-docs.yaml +++ b/.github/workflows/build-docs.yaml @@ -1,5 +1,5 @@ --- -name: Release Collection +name: Build Docs on: # yamllint disable-line rule:truthy workflow_dispatch: From c5ffdb7bdaedf7e41155ac7f66672aac7ee5ee9f Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Mon, 23 May 2022 13:55:32 +0200 Subject: [PATCH 17/18] Add docs building to release action. --- .github/workflows/build-docs.yaml | 32 ----------------------- .github/workflows/release.yaml | 42 ++++++++++++++++++++++++++----- .gitignore | 1 + requirements.txt | 3 ++- 4 files changed, 39 insertions(+), 39 deletions(-) delete mode 100644 .github/workflows/build-docs.yaml diff --git a/.github/workflows/build-docs.yaml b/.github/workflows/build-docs.yaml deleted file mode 100644 index e0957925e..000000000 --- a/.github/workflows/build-docs.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Build Docs -on: # yamllint disable-line rule:truthy - workflow_dispatch: - -jobs: - release: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Get current version - id: current_version - run: echo "::set-output name=version::$(grep 'version:' galaxy.yml | cut -d ' ' -f 2)" - - - name: Set up Python. - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - - name: Install Dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: Compile Collection Changelog - run: antsibull-changelog release - - - name: Compile Collection Docs - run: antsibull-docs collection --use-current --squash-hierarchy --dest-dir ./docs/ tribe29.checkmk diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index acf90d116..35b8a6a38 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,6 +8,11 @@ jobs: runs-on: ubuntu-latest steps: + + # + # Prepare the environment. + # + - name: Checkout code uses: actions/checkout@v2 @@ -25,9 +30,31 @@ jobs: python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + # + # First stage: Build and install collection to generate docs and changelogs. + # + + - name: Copy Files and Directories to Source + run: | + mkdir -p build/src + cp $files build/src + cp -rf $directories build/src + env: + files: "CHANGELOG.rst LICENSE README.md ansible.cfg galaxy.yml" + directories: "changelogs docs meta playbooks plugins roles" + + - name: Build Ansible Collection + run: ansible-galaxy collection build build/src --force + + - name: Install Ansible Collection + run: ansible-galaxy collection install ./tribe29-checkmk-${{ steps.current_version.outputs.version }}.tar.gz + - name: Compile Collection Changelog run: antsibull-changelog release + - name: Compile Collection Docs + run: antsibull-docs collection --use-current --squash-hierarchy --fail-on-error --dest-dir ./docs/ tribe29.checkmk + # https://github.com/marketplace/actions/create-pull-request - name: Create Pull Request for docs uses: peter-evans/create-pull-request@v3 @@ -36,15 +63,19 @@ jobs: committer: GitHub author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> signoff: false - branch: changelogs-update + branch: changelogs-docs-update delete-branch: true - title: '[Auto] Update changelogs' + title: '[Auto] Update changelogs and docs' body: | - Changelogs updated during *${{ steps.current_version.outputs.version }}* release. + Changelogs and docs updated during *${{ steps.current_version.outputs.version }}* release. assignees: robin-tribe29 reviewers: robin-tribe29 draft: false + # + # Second stage: Build the final version of the collection and release it. + # + - name: Copy Files and Directories to Source run: | mkdir -p build/src @@ -52,8 +83,7 @@ jobs: cp -rf $directories build/src env: files: "CHANGELOG.rst LICENSE README.md ansible.cfg galaxy.yml" - # directories: "playbooks plugins roles vars" - directories: "changelogs docs meta playbooks plugins" + directories: "changelogs docs meta playbooks plugins roles" - name: Build Ansible Collection run: ansible-galaxy collection build build/src --force @@ -65,7 +95,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: v${{ steps.current_version.outputs.version }} - release_name: Release v${{ steps.current_version.outputs.version }} + release_name: v${{ steps.current_version.outputs.version }} body: | # Ansible Collection: tribe29.checkmk diff --git a/.gitignore b/.gitignore index 164af500e..ccb3eec83 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .*.swo *~ .vagrant/ +build/ tests/output playbooks/vars/config.yml playbooks/test.yml \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7cc4172cb..795de5222 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ ansible >= 4.10.0 -antsibull-changelog >= 0.12.0 \ No newline at end of file +antsibull-changelog >= 0.12.0 +antsibull-docs >= 1.1.0 \ No newline at end of file From d50ea14a89533a6c3014fe51da2aec0a1ed5741a Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Mon, 23 May 2022 14:13:27 +0200 Subject: [PATCH 18/18] Prepare release. --- galaxy.yml | 2 +- requirements.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 requirements.yml diff --git a/galaxy.yml b/galaxy.yml index 33d403de0..e0e842300 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -9,7 +9,7 @@ namespace: tribe29 name: checkmk # The version of the collection. Must be compatible with semantic versioning -version: 0.2.2 +version: 0.3.2 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 000000000..db52f7582 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,4 @@ +--- +collections: + - name: tribe29.checkmk + version: 0.3.2