From 93f02d186f0ab78d97ce46bb619fe3f36197783c Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Sun, 19 Mar 2017 23:52:38 +0100 Subject: [PATCH 1/4] Add support for installing Check_MK extension packages (MKP) --- defaults/main.yml | 7 +++++++ docs/defaults-configuration.rst | 21 +++++++++++++++++++++ docs/getting-started.rst | 3 +++ tasks/site.yml | 30 ++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index 1e03a12..13350be 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -618,6 +618,13 @@ checkmk_server__site_cfg_netif_description: wato: False +# .. envvar:: checkmk_server__site_packages +# +# Additional Check_MK packages (MKP) to be installed. See +# :ref:`checkmk_server__site_packages` for more information. +checkmk_server__site_packages: [] + + # ----------------- # PKI Configuration # ----------------- diff --git a/docs/defaults-configuration.rst b/docs/defaults-configuration.rst index 24b3561..1eeb9d6 100644 --- a/docs/defaults-configuration.rst +++ b/docs/defaults-configuration.rst @@ -56,6 +56,27 @@ following keys: key set with ``privatekey_file``. +.. _checkmk_server__site_packages: + +checkmk_server__site_packages +----------------------------- + +Check_MK has a plugin system where site customizations such as additional +checks can be installed. This is done via ``.mkp`` packages. For more +information see the upstream documentation about `Check_MK extension packages`_. + +.. _Check_MK extension packages: https://mathias-kettner.com/cms_mkps.html + +Packages which should be installed for the current Check_MK site are defined +as a list of YAML dictionaries with the following configuration keys: + +``name`` + Name of the package, required. + +``url`` + Download URL of the ``.mkp`` package archive, required. + + .. _checkmk_server__multisite_users: checkmk_server__multisite_users diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 11da33f..0d451b9 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -52,3 +52,6 @@ Available role tags: ``role::checkmk_server:multisite`` Execute tasks which configure the Check_MK multisite Web interface. + +``role::checkmk_server:mkp`` + Execute tasks to install Check_MK packages. diff --git a/tasks/site.yml b/tasks/site.yml index 64fe6d5..f81619c 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -139,3 +139,33 @@ ignore_errors: '{{ ansible_check_mode }}' register: checkmk_server__register_ssh_public_key when: checkmk_server__sshkeys|d() + +- name: Query installed Check_MK packages + command: mkp list + become_user: '{{ checkmk_server__user }}' + become_flags: '-i' + changed_when: False + always_run: True + register: checkmk_server__register_mkp + tags: + - 'role::checkmk_server:mkp' + +- name: Download Check_MK packages + get_url: + url: '{{ item.url }}' + dest: '{{ checkmk_server__site_home }}/tmp' + when: ('url' in item) and + (item.name not in checkmk_server__register_mkp.stdout_lines) + register: checkmk_server__register_mkp_download + with_items: '{{ checkmk_server__site_packages }}' + tags: + - 'role::checkmk_server:mkp' + +- name: Install Check_MK packages + command: mkp install '{{ item.dest|d() }}' + become_user: '{{ checkmk_server__user }}' + become_flags: '-i' + when: not item.skipped + with_items: '{{ checkmk_server__register_mkp_download.results }}' + tags: + - 'role::checkmk_server:mkp' From 344dc705cc1decb882d7e72e95d939473c906940 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 21 Mar 2017 07:02:52 +0100 Subject: [PATCH 2/4] Correctly used skipped filter --- tasks/site.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/site.yml b/tasks/site.yml index f81619c..16de5dd 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -165,7 +165,7 @@ command: mkp install '{{ item.dest|d() }}' become_user: '{{ checkmk_server__user }}' become_flags: '-i' - when: not item.skipped + when: not (item | skipped) with_items: '{{ checkmk_server__register_mkp_download.results }}' tags: - 'role::checkmk_server:mkp' From 5335762b32ef41bcb4fdf41cdad97f82811039bc Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 21 Mar 2017 07:24:47 +0100 Subject: [PATCH 3/4] Add support for also uploading local package archives --- docs/defaults-configuration.rst | 9 +++++++-- tasks/site.yml | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/defaults-configuration.rst b/docs/defaults-configuration.rst index 1eeb9d6..d8b422c 100644 --- a/docs/defaults-configuration.rst +++ b/docs/defaults-configuration.rst @@ -68,13 +68,18 @@ information see the upstream documentation about `Check_MK extension packages`_. .. _Check_MK extension packages: https://mathias-kettner.com/cms_mkps.html Packages which should be installed for the current Check_MK site are defined -as a list of YAML dictionaries with the following configuration keys: +as a list of YAML dictionaries with the following configuration keys. One of +``path`` or ``url`` must be given: ``name`` Name of the package, required. +``path`` + Optional. Local file system path of the ``.mkp`` package archive on the + Ansible controller. + ``url`` - Download URL of the ``.mkp`` package archive, required. + Optional. Download URL of the ``.mkp`` package archive. .. _checkmk_server__multisite_users: diff --git a/tasks/site.yml b/tasks/site.yml index 16de5dd..c54c0bd 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -161,11 +161,24 @@ tags: - 'role::checkmk_server:mkp' +- name: Upload Check_MK packages + copy: + src: '{{ item.path }}' + dest: '{{ checkmk_server__site_home }}/tmp' + when: ('path' in item) and + (item.name not in checkmk_server__register_mkp.stdout_lines) + register: checkmk_server__register_mkp_upload + with_items: '{{ checkmk_server__site_packages }}' + tags: + - 'role::checkmk_server:mkp' + - name: Install Check_MK packages command: mkp install '{{ item.dest|d() }}' become_user: '{{ checkmk_server__user }}' become_flags: '-i' when: not (item | skipped) - with_items: '{{ checkmk_server__register_mkp_download.results }}' + with_flattened: + - '{{ checkmk_server__register_mkp_download.results }}' + - '{{ checkmk_server__register_mkp_upload.results }}' tags: - 'role::checkmk_server:mkp' From ede8dba4185cbdfbba09f492eefa07c98e44d69f Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 21 Mar 2017 18:12:41 +0100 Subject: [PATCH 4/4] Add optional parameter 'checksum' to package download --- docs/defaults-configuration.rst | 12 ++++++++++-- tasks/site.yml | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/defaults-configuration.rst b/docs/defaults-configuration.rst index d8b422c..b40a425 100644 --- a/docs/defaults-configuration.rst +++ b/docs/defaults-configuration.rst @@ -76,10 +76,18 @@ as a list of YAML dictionaries with the following configuration keys. One of ``path`` Optional. Local file system path of the ``.mkp`` package archive on the - Ansible controller. + Ansible controller. Cannot be combined with the ``url`` parameter. ``url`` - Optional. Download URL of the ``.mkp`` package archive. + Optional. Download URL of the ``.mkp`` package archive. Cannot be combined + with the ``path`` parameter. + +``checksum`` + Optional. Checksum of the download archive given in the ``url`` parameter. + Cannot be combined with the ``path`` parameter. For the accepted parameter + format check the Ansible `get_url module`_ documentation. + +.. _get_url module: https://docs.ansible.com/ansible/get_url_module.html#options .. _checkmk_server__multisite_users: diff --git a/tasks/site.yml b/tasks/site.yml index c54c0bd..b7c178c 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -154,6 +154,7 @@ get_url: url: '{{ item.url }}' dest: '{{ checkmk_server__site_home }}/tmp' + checksum: '{{ item.checksum|d(omit) }}' when: ('url' in item) and (item.name not in checkmk_server__register_mkp.stdout_lines) register: checkmk_server__register_mkp_download