ansible-homelab/playbooks/update-checkmk.yml
2026-03-15 04:41:37 +01:00

88 lines
3.0 KiB
YAML

- name: Gather latest checkmk version
hosts: all
tasks:
# cannot be done with git module. It has no method to query the tags of a repo
- name: Get latest checkmk version # noqa: run-once[task] command-instead-of-module
register: checkmk_version
delegate_to: localhost
changed_when: false
ansible.builtin.shell:
executable: /bin/bash
cmd: |
set -o pipefail
git -c 'versionsort.suffix=-' \
ls-remote --tags --sort='v:refname' \
https://github.com/Checkmk/checkmk.git |\
grep -v '\-rc.' | tail --lines=1 |\
cut --delimiter='/' --fields=3 | tr -d "v^{}"
- name: Output checkmk version # noqa: run-once[task]
run_once: true
ansible.builtin.debug:
var: checkmk_version.stdout
- name: Set checkmk version fact # noqa: run-once[task]
run_once: true
ansible.builtin.set_fact:
checkmk_version: "{{ checkmk_version.stdout }}"
- name: Update checkmk on monitoring hosts
hosts: sites
become: true
tasks:
- name: Snapshot VM before update
become: false
delegate_to: localhost
community.proxmox.proxmox_snap:
api_host: "{{ proxmox_api_host }}"
api_user: "{{ proxmox_api_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}"
validate_certs: false
hostname: "{{ inventory_hostname_short }}"
snapname: "checkmk_{{ checkmk_version | replace('.', '_') | replace('-', '_') }}"
description: "Pre-update snapshot before checkmk {{ checkmk_version }}"
timeout: 120
state: present
- name: Install new checkmk version
vars:
filename: "check-mk-raw-{{ checkmk_version }}_0.{{ ansible_facts.lsb.codename }}_amd64.deb"
ansible.builtin.apt:
deb: "https://download.checkmk.com/checkmk/{{ checkmk_version }}/{{ filename }}"
when: ansible_facts.lsb.id == 'Ubuntu'
- name: Stop omd sites
register: stop_cmd
changed_when: stop_cmd.rc == 0
loop: "{{ checkmk_sites }}"
ansible.builtin.command: "omd stop {{ item }}"
- name: Create backup of site (/tmp/backup-{{ item }}.tar.gz)
changed_when: true
loop: "{{ checkmk_sites }}"
ansible.builtin.command: "omd backup {{ item }} /tmp/backup-{{ item }}.tar.gz"
- name: Update omd site
changed_when: true
loop: "{{ checkmk_sites }}"
ansible.builtin.command: "omd -f update --conflict=keepold {{ item }}"
- name: Start omd sites
register: start_cmd
changed_when: start_cmd.rc == 0
loop: "{{ checkmk_sites }}"
ansible.builtin.command: "omd start {{ item }}"
- name: Update checkmk agents on monitored hosts
hosts: agents
become: true
tasks:
- name: Install new checkmk agent
ansible.builtin.apt:
deb: "https://checkmk.stuyckv.com/local/check_mk/agents/check-mk-agent_{{ checkmk_version }}-1_all.deb"
when: ansible_facts.lsb.id == 'Ubuntu'