Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Enable management of MKP packages with server role #714

Open
wants to merge 14 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions roles/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ Note: this is not a recommended procedure, and will not be supported for enterpr
omd_config:
- var: AUTOSTART
value: 'on'
mkp_packages:
- name: 'mypackage'
version: 1.0
src: 'path'
url: 'download'
checksum: 'md5:download checksum'
installed: true
enabled: true

A dictionary of sites, containing the desired version, admin password and state.
MKP packages can be listed to be installed on the specific site. A source can be set on the ansible controller. Alternatively a url can be specified to download the mkp package from.
Comment on lines +85 to +95
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, if this is getting to convoluted here, but I got no better idea, so I am just mentioning it.

There are also advanced settings, which will be outlined below.

Valid values for `state` are:
Expand Down
2 changes: 2 additions & 0 deletions roles/server/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ checkmk_server_epel_gpg_check: 'true'

checkmk_server_cleanup: 'false'
checkmk_server_no_log: 'true'

checkmk_server_mkp_staging: '/tmp'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a global tmp dir variable, like in the agent role: __checkmk_agent_host_tmp_dir.
That should obviously be done in a dedicated PR ahead of this one. Would you want to take that on @ra2xfael?

But why make it configurable in the first place?

76 changes: 76 additions & 0 deletions roles/server/tasks/mkp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
- name: "Download MKP Packages."
ansible.builtin.get_url:
url: "{{ __mkp.url }}"
dest: "{{ checkmk_server_mkp_staging }}/{{ __mkp.name }}-{{ __mkp.version }}.mkp"
mode: "0640"
url_username: "{{ __mkp.download_user | default(omit) }}"
url_password: "{{ __mkp.download_password | default(omit) }}"
checksum: "{{ __mkp.checksum | default(omit) }}"
retries: 3
loop: "{{ __site.mkp_packages }}"
loop_control:
loop_var: __mkp
when: __mkp.url is defined
tags:
- manage-mkp-packages

- name: "Copy MKP Packages."
ansible.builtin.copy:
src: "{{ __mkp.src }}"
dest: "{{ checkmk_server_mkp_staging }}/{{ __mkp.name }}-{{ __mkp.version }}.mkp"
mode: "0640"
loop: "{{ __site.mkp_packages }}"
loop_control:
loop_var: __mkp
when: __mkp.src is defined
tags:
- manage-mkp-packages

- name: "Install mkp packages."
become: true
ansible.builtin.command: "omd su {{ __site.name }} -c mkp add {{ checkmk_server_mkp_staging }}/{{ __mkp.name }}-{{ __mkp.version }}.mkp"
changed_when: __checkmk_server_mkp_install_output.rc == 0
register: __checkmk_server_mkp_install_output
loop: "{{ __site.mkp_packages }}"
loop_control:
loop_var: __mkp
when: (__mkp.installed | default(true) )
tags:
- manage-mkp-packages

- name: "Enable mkp packages."
become: true
ansible.builtin.command: "omd su {{ __site.name }} -c mkp enable {{ __mkp.name }} {{ __mkp.version }}"
changed_when: __checkmk_server_mkp_enable_output.rc == 0
register: __checkmk_server_mkp_enable_output
loop: "{{ __site.mkp_packages }}"
loop_control:
loop_var: __mkp
when: (__mkp.enabled | default(true))
tags:
- manage-mkp-packages

- name: "Disable mkp packages."
become: true
ansible.builtin.command: "omd su {{ __site.name }} -c mkp disable {{ __mkp.name }} {{ __mkp.version }}"
changed_when: __checkmk_server_mkp_disable_output.rc == 0
register: __checkmk_server_mkp_disable_output
loop: "{{ __site.mkp_packages }}"
loop_control:
loop_var: __mkp
when: __mkp.enabled is defined and not __mkp.enabled
tags:
- manage-mkp-packages

- name: "Remove mkp packages."
become: true
ansible.builtin.command: "omd su {{ __site.name }} -c mkp remove {{ __mkp.name }} {{ __mkp.version }}"
changed_when: __checkmk_server_mkp_remove_output.rc == 0
register: __checkmk_server_mkp_remove_output
loop: "{{ __site.mkp_packages }}"
loop_control:
loop_var: __mkp
when: __mkp.installed is defined and not __mkp.installed
tags:
- manage-mkp-packages
7 changes: 7 additions & 0 deletions roles/server/tasks/sites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@
tags:
- configure-sites

- name: "Configure MKP packages."
ansible.builtin.include_tasks: mkp.yml
loop: "{{ checkmk_server_sites }}"
loop_control:
loop_var: __site
when: __site.mkp_packages is defined

- name: "Update Site Admin Password for Checkmk < 2.1." # noqa no-changed-when
become: true
ansible.builtin.shell: |
Expand Down