generated from GamingChaos/ansible-repository-template
Compare commits
5 Commits
5b4f9f2942
...
21b3b528cf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21b3b528cf | ||
|
|
e35c1cbf3c | ||
|
|
ce33e8a689 | ||
|
|
79c3952e64 | ||
|
|
d7b53b1cf5 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1 @@
|
||||
# ---> Ansible
|
||||
*.retry
|
||||
|
||||
venv/
|
||||
|
||||
8
init.sh
Executable file
8
init.sh
Executable file
@ -0,0 +1,8 @@
|
||||
|
||||
# initialize venv
|
||||
python3 -m venv venv
|
||||
. ./venv/bin/activate
|
||||
|
||||
pip install -r requirements.txt
|
||||
|
||||
ansible-galaxy collection install -r requirements.yml
|
||||
4
inventory/group_vars/sites/proxmox.yml
Normal file
4
inventory/group_vars/sites/proxmox.yml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
proxmox_api_host: rimeru.stuyckv.local
|
||||
proxmox_api_user: ansible@pve
|
||||
proxmox_api_token_id: ansible
|
||||
9
inventory/group_vars/sites/vault.yml
Normal file
9
inventory/group_vars/sites/vault.yml
Normal file
@ -0,0 +1,9 @@
|
||||
$ANSIBLE_VAULT;1.1;AES256
|
||||
66393831316666346565393032333961373365346633643730386661616332356431653331396334
|
||||
3633373066646165636639646462376338366665376561650a643530306339666436323130383737
|
||||
36373532623435336466386433326664356537326137363537343133323739343732383565346336
|
||||
6630636236363261610a646336613436323462663339313364393833653539653238666437623261
|
||||
65383864346165623730363136353838396131643962393134366362393266356365396231633064
|
||||
65366631653437626666343465383338383637373139353130623961316662353431313037303834
|
||||
36356131323233613461333163303537306635343065663435333961376264316235643335323661
|
||||
36336331336537343432
|
||||
@ -1,5 +1,4 @@
|
||||
[ubuntu]
|
||||
charybdis.stuyckv.local
|
||||
shion.stuyckv.local
|
||||
charybdis.stuyckv.local
|
||||
ramiris.stuyckv.local
|
||||
|
||||
5
inventory/host_vars/shion.stuyckv.local.yml
Normal file
5
inventory/host_vars/shion.stuyckv.local.yml
Normal file
@ -0,0 +1,5 @@
|
||||
checkmk_sites:
|
||||
- local
|
||||
- dev
|
||||
|
||||
vmid: 101
|
||||
12
inventory/monitoring
Normal file
12
inventory/monitoring
Normal file
@ -0,0 +1,12 @@
|
||||
[sites]
|
||||
shion.stuyckv.local
|
||||
|
||||
[agents]
|
||||
rimeru.stuyckv.local
|
||||
shion.stuyckv.local
|
||||
charybdis.stuyckv.local
|
||||
ramiris.stuyckv.local
|
||||
millim.stuyckv.local
|
||||
guy.stuyckv.local
|
||||
claymen.stuyckv.local
|
||||
leon.stuyckv.local
|
||||
68
playbooks/update-checkmk.yml
Normal file
68
playbooks/update-checkmk.yml
Normal file
@ -0,0 +1,68 @@
|
||||
- name: Update checkmk on monitoring hosts
|
||||
hosts: sites
|
||||
become: true
|
||||
|
||||
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
|
||||
run_once: true
|
||||
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: 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.stdout | replace('.', '_') | replace('-', '_') }}"
|
||||
description: "Pre-update snapshot before checkmk {{ checkmk_version.stdout }}"
|
||||
timeout: 120
|
||||
state: present
|
||||
|
||||
- name: Install new checkmk version
|
||||
vars:
|
||||
filename: "check-mk-raw-{{ checkmk_version.stdout }}_0.{{ ansible_facts.lsb.codename }}_amd64.deb"
|
||||
ansible.builtin.apt:
|
||||
deb: "https://download.checkmk.com/checkmk/{{ checkmk_version.stdout }}/{{ 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 }}"
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
proxmoxer
|
||||
requests
|
||||
4
requirements.yml
Normal file
4
requirements.yml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
collections:
|
||||
- name: community.proxmox
|
||||
version: "1.6.0"
|
||||
Loading…
x
Reference in New Issue
Block a user