Initial commit
This commit is contained in:
134
ansible/roles/linstor_ha/tasks/main.yml
Normal file
134
ansible/roles/linstor_ha/tasks/main.yml
Normal file
@@ -0,0 +1,134 @@
|
||||
---
|
||||
# tasks file for linstor_ha
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# STEP 1: CREATE HA RESOURCES (Executed ONLY on Node 1)
|
||||
# ---------------------------------------------------------
|
||||
- name: Create HA Resource Group and Spawn Database Volume
|
||||
ansible.builtin.shell: |
|
||||
set -o pipefail
|
||||
if ! linstor resource-group list | grep -q " linstor-db-grp "; then
|
||||
linstor resource-group create --storage-pool "{{ ha_pool }}" --place-count 3 --diskless-on-remaining true linstor-db-grp > /dev/null
|
||||
linstor resource-group drbd-options --auto-promote=no --quorum=majority \
|
||||
--on-suspended-primary-outdated=force-secondary --on-no-quorum=io-error --on-no-data-accessible=io-error linstor-db-grp > /dev/null
|
||||
linstor volume-group create linstor-db-grp > /dev/null
|
||||
linstor resource-group spawn-resources linstor-db-grp linstor_db 200M > /dev/null
|
||||
echo "changed"
|
||||
fi
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: linstor_ha_rg_create
|
||||
changed_when: "'changed' in linstor_ha_rg_create.stdout"
|
||||
when: inventory_hostname == groups['proxmox'][0]
|
||||
|
||||
- name: Wait for DRBD block device to appear locally
|
||||
ansible.builtin.wait_for:
|
||||
path: /dev/drbd/by-res/linstor_db/0
|
||||
state: present
|
||||
timeout: 60
|
||||
when: inventory_hostname == groups['proxmox'][0]
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# STEP 2: PREPARE ALL NODES
|
||||
# ---------------------------------------------------------
|
||||
- name: Install resource-agents
|
||||
ansible.builtin.apt:
|
||||
name: resource-agents
|
||||
state: present
|
||||
|
||||
- name: Ensure local Linstor Controller is stopped and disabled
|
||||
ansible.builtin.systemd:
|
||||
name: linstor-controller
|
||||
enabled: false
|
||||
state: stopped
|
||||
|
||||
- name: Deploy var-lib-linstor.mount unit
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/systemd/system/var-lib-linstor.mount
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Filesystem for the LINSTOR controller
|
||||
|
||||
[Mount]
|
||||
What=/dev/drbd/by-res/linstor_db/0
|
||||
Where=/var/lib/linstor
|
||||
mode: '0644'
|
||||
|
||||
- name: Ensure drbd-reactor directory exists
|
||||
ansible.builtin.file:
|
||||
path: /etc/drbd-reactor.d
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Deploy DRBD Reactor TOML config
|
||||
ansible.builtin.template:
|
||||
src: linstor_db.toml.j2
|
||||
dest: /etc/drbd-reactor.d/linstor_db.toml
|
||||
mode: '0644'
|
||||
|
||||
# Notice how the stat task is gone, replaced by 'creates' and 'removes'
|
||||
- name: Move existing local database to .orig safely
|
||||
ansible.builtin.command: mv /var/lib/linstor /var/lib/linstor.orig
|
||||
args:
|
||||
creates: /var/lib/linstor.orig
|
||||
removes: /var/lib/linstor
|
||||
|
||||
- name: Create empty mount point and set immutable flag (+i)
|
||||
ansible.builtin.file:
|
||||
path: /var/lib/linstor
|
||||
state: directory
|
||||
mode: '0755'
|
||||
attributes: '+i'
|
||||
|
||||
- name: Ensure Satellite Override directory exists
|
||||
ansible.builtin.file:
|
||||
path: /etc/systemd/system/linstor-satellite.service.d
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Deploy Satellite Keep-Resource Override
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/systemd/system/linstor-satellite.service.d/override.conf
|
||||
content: |
|
||||
[Service]
|
||||
Environment=LS_KEEP_RES=linstor_db
|
||||
mode: '0644'
|
||||
|
||||
- name: Reload daemon and restart Satellite
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
||||
name: linstor-satellite
|
||||
state: restarted
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# STEP 3: FORMAT & MIGRATE DB (Executed ONLY on Node 1)
|
||||
# ---------------------------------------------------------
|
||||
- name: Format HA Volume and Migrate Database
|
||||
ansible.builtin.shell: |
|
||||
set -o pipefail
|
||||
if ! blkid /dev/drbd/by-res/linstor_db/0 | grep -q "ext4"; then
|
||||
drbdadm primary linstor_db
|
||||
mkfs.ext4 /dev/drbd/by-res/linstor_db/0 > /dev/null
|
||||
|
||||
chattr -i /var/lib/linstor
|
||||
mount /dev/drbd/by-res/linstor_db/0 /var/lib/linstor
|
||||
cp -a /var/lib/linstor.orig/* /var/lib/linstor/
|
||||
umount /var/lib/linstor
|
||||
chattr +i /var/lib/linstor
|
||||
drbdadm secondary linstor_db
|
||||
echo "changed"
|
||||
fi
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: linstor_ha_migrate
|
||||
changed_when: "'changed' in linstor_ha_migrate.stdout"
|
||||
when: inventory_hostname == groups['proxmox'][0]
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# STEP 4: ACTIVATE HA REACTOR
|
||||
# ---------------------------------------------------------
|
||||
- name: Enable and start DRBD Reactor
|
||||
ansible.builtin.systemd:
|
||||
name: drbd-reactor
|
||||
enabled: true
|
||||
state: started
|
||||
Reference in New Issue
Block a user