How to download latest version of MK programatically

Hi there,
I have a playbook that updates my Checkmk installation to the latest version and deploys the latest agents to all my hosts. I download and install the latest server version like this:

---
- name: update check_mk server
  hosts: localhost
  gather_facts: no
  tasks:
    - name: download latest check_mk server package
      ansible.builtin.get_url:
        url: https://download.checkmk.com/checkmk/2.1.0b7/check-mk-raw-2.1.0b7-sles15sp3-38.x86_64.rpm
        dest: /tmp/check-mk-raw-latest.x86_64.rpm
      register: new_server
    - name: install latest check_mk server package
      ansible.builtin.package:
        name: /tmp/check-mk-raw-latest.x86_64.rpm
        state: present
        disable_gpg_check: yes
      when: new_server.changed
    - name: stop site
      ansible.builtin.command: omd stop home
      when: new_server.changed
    - name: update site
      ansible.builtin.command: omd -f -V 2.1.0b7.cre update --conflict=install home
      when: new_server.changed
    - name: start site
      ansible.builtin.command: omd start home
      when: new_server.changed

I’m looking for a way to automatically grab the latest version (beta if available, stable otherwise) rather than having to edit that URL each time I want to run my playbook. I look at parsing the code behind Download archive of outdated Checkmk versions or Download Checkmk for free | Checkmk but this is incredibly complicated due to how the download link is dynamically generated. There must be a better way?

Well, you pull the open source version, so the link is easy to construct in general, but I see your struggle.
@baris.leenders do you see an easy implementable approach to enable users to download the latest (beta) version through a generic link?

1 Like

This is something I have wanted to implement before. Only the maintainability stopped me from doing it. Since we are working on the download page and related topics, maybe it is worth revisiting the topic.
I will let you know here, in a few weeks, what the outcome will be.

2 Likes

You sir, are a very brave man.

(sorry for assuming your gender)

4 Likes

I would rather stay with official (whether stable or beta) releases than pulling directly from the git (which is something I did consider and yes that would be easier to automate as things currently stand). From what I can see on the git there is a separate branch for major releases but not for every patch level.

There is a json on the download page (downloads='{...}') but Ansible doesn’t make it super easy to parse through the whole webpage, find the json and then work with the json and there is no guarantee that this won’t change in the future. If that json was loaded from a dedicated json file it would be much easier to parse the json file directly with Ansible (or any other automation tool) and get the info we need from here to build the download link correctly.

No problem. We started automating installations with Ansible at my workplace, so I decided to automate with Ansible updates to my own Checkmk installation in my homelab to learn a little bit more about Ansible (and Checkmk). While at work we very rarely update Checkmk (once a year at best), I like to stay up to date with the latest features in my homelab, so having a playbook run once every day and automatically update when an update is available is always something I wanted to do. Currently I just change the rpm URL path once I get notified about a new update but removing any manual intervention would be even cooler.

@dnLL

there is a JSON blob in the source of the download URL, there you can “grep” all the data from you need. I use this in my CMK update check, so have a look if you like :slight_smile:
Checkmk Updates

2 Likes

I do a similar thing with the agent installation. My solution includes an internally available HTTP folder containing the agent files, and a symlink called “agent-latest.rpm” which I point at the new files when I generate them. You could do a similar thing - download it once, put it in a shared location called “checkmk-server-latest.rpm” and reference that in your playbook.

Not totally automatic like you asked, but probably much safer. Checkmk generally dislikes having different versions running within a distributed setup, if a new version were to be released in between you doing updates/installations of different hosts you might find yourself in a pickle.

You could also solve this in the opposite way. Given that you need the version number several times in the playbook, look it up yourself and supply it as a variable.

We are rebuilding the download page and plan to launch it this month. The JSON blob will be split into several ones as far as I know as the one just got too large now. The structure stays mostly the same I think, but instead of one super big JSON, we will have several smaller ones.
Thus, be aware as it will likely impact you.

@martin.hirschvogel thanks for the heads up. Sounds after some work for me :wink:

Very interesting, parsing with Python seems to make it easier than strictly with Ansible in this specific case.

Thanks for the heads up, I will wait a little bit in this case. If the JSONs could be in separate files rather than directly within the download page, it could almost be called like a REST API rather than having to parse the webpage for the JSONs.

Alternatively if the raw/free versions were in a different directory that is not password protected and allows listing, that would work as well.

For our Linux infrastucture running CentOS 7 and Alma Linux 8, we use Foreman/Katello to manage our packages for all Linux servers.
I have created a local repository that I maintain with all CheckMK packages, I will then manually download the RPM from Tribe29 and upload it to our CheckMK repo in Katello, then all servers have access to it via normal installation method. We run Managed Enterprice Edition and use the bakery to update our agents. But the CheckMK servers are updated using scripts as well.

Works really well.