Compare commits

...
3 Commits
2 changed files with 31 additions and 4 deletions
+2 -2
View File
@@ -37,8 +37,8 @@ The `# noqa:` annotations in the playbooks are for ansible-lint (`ansible-lint p
- `update-checkmk.yml` has three plays that share state through a fact: - `update-checkmk.yml` has three plays that share state through a fact:
1. On `all` hosts, delegated to localhost, it gets the latest stable Checkmk tag from GitHub with `git ls-remote` and sets `checkmk_version`. It targets `all` on purpose: a `set_fact` only applies to the hosts in its own play, so `sites` and `agents` would lose the fact if the play ran only on `localhost` (or they'd have to read `hostvars['localhost'].checkmk_version`). 1. On `all` hosts, delegated to localhost, it gets the latest stable Checkmk tag from GitHub with `git ls-remote` and sets `checkmk_version`. It targets `all` on purpose: a `set_fact` only applies to the hosts in its own play, so `sites` and `agents` would lose the fact if the play ran only on `localhost` (or they'd have to read `hostvars['localhost'].checkmk_version`).
2. On `sites`, it snapshots the VM through the Proxmox API (delegated to localhost, using `inventory_hostname_short` as the Proxmox VM name), installs the community-edition `.deb`, then runs `omd stop`, `backup`, `update` and `start` for each entry in `checkmk_sites`. 2. On `sites`, it reads the installed version with `omd version -b` (as the login user, no `become`) and ends the play for that host (`meta: end_host`) when it already matches `checkmk_version`. Otherwise it snapshots the VM through the Proxmox API (delegated to localhost, using `inventory_hostname_short` as the Proxmox VM name), installs the community-edition `.deb`, then runs `omd stop`, `backup`, `update` and `start` for each entry in `checkmk_sites`.
3. On `agents`, it installs the agent `.deb` from the local Checkmk server (`checkmk.stuyckv.com/local`). 3. On `agents`, it installs the agent `.deb` from the local Checkmk server (`checkmk.stuyckv.com/local`), then registers the agent for TLS with `cmk-agent-ctl register`, using the `checkmk_api_*` vars. It registers on every run on purpose, because registering again renews the agent certificate. `checkmk.general` has an `agent` role but no `agent` module, so this is done with a plain command.
Package installs only run when `ansible_facts.lsb.id == 'Ubuntu'`. Package installs only run when `ansible_facts.lsb.id == 'Ubuntu'`.
- `update-debian.yml` runs against `ubuntu`. It sets a Checkmk downtime through `checkmk.general`, then runs dist-upgrade, reboots if needed and autoremoves. Like the Proxmox snapshot, the downtime task is delegated to localhost with `become: false`. - `update-debian.yml` runs against `ubuntu`. It sets a Checkmk downtime through `checkmk.general`, then runs dist-upgrade, reboots if needed and autoremoves. Like the Proxmox snapshot, the downtime task is delegated to localhost with `become: false`.
+29 -2
View File
@@ -32,6 +32,17 @@
become: true become: true
tasks: tasks:
- name: Get current checkmk version
become: false
register: current_version
changed_when: false
ansible.builtin.command: omd version -b
# omd appends the edition to the version (e.g. 2.4.0p12.cre), the git tag doesn't
- name: Stop when checkmk is up to date
when: current_version.stdout | regex_replace('[.][a-z]+$', '') == checkmk_version
ansible.builtin.meta: end_host
- name: Snapshot VM before update - name: Snapshot VM before update
become: false become: false
delegate_to: localhost delegate_to: localhost
@@ -80,9 +91,25 @@
- name: Update checkmk agents on monitored hosts - name: Update checkmk agents on monitored hosts
hosts: agents hosts: agents
become: true become: true
vars:
checkmk_server: "shion.stuyckv.local"
tasks: tasks:
- name: Install new checkmk agent - name: Install new checkmk agent
ansible.builtin.apt: ansible.builtin.apt:
deb: "https://checkmk.stuyckv.com/local/check_mk/agents/check-mk-agent_{{ checkmk_version }}-1_all.deb" deb: "http://{{ checkmk_server }}/local/check_mk/agents/check-mk-agent_{{ checkmk_version }}-1_all.deb"
when: ansible_facts.lsb.id == 'Ubuntu' when: ansible_facts.os_family == 'Debian'
# registering again renews the agent certificate
- name: Register agent with the site
changed_when: true
ansible.builtin.command:
argv:
- cmk-agent-ctl
- register
- --trust-cert
- --hostname={{ inventory_hostname }}
- --server={{ checkmk_server }}
- --site={{ checkmk_api_site }}
- --user={{ checkmk_api_user }}
- --password={{ checkmk_api_secret }}