70 lines
2.7 KiB
YAML
70 lines
2.7 KiB
YAML
---
|
|
# tasks file for linstor_storage
|
|
|
|
- name: Configure LVM global_filter for DRBD safely
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/lvm/lvm.conf
|
|
insertafter: '^[ \t]*devices[ \t]*\{'
|
|
# This regex ensures we only ever have ONE DRBD filter line, replacing the old one if it exists
|
|
regexp: '^[ \t]*global_filter[ \t]*=.*r\|\^/dev/drbd\|'
|
|
line: ' global_filter = [ "r|^/dev/drbd|", "r|^/dev/mapper/[lL]instor|" ]'
|
|
state: present
|
|
|
|
- name: Ensure Volume Groups exist for raw disks
|
|
community.general.lvg:
|
|
vg: "{{ item.vg_name }}"
|
|
pvs: "{{ item.targets[inventory_hostname] }}"
|
|
loop: "{{ linstor_storage_pools }}"
|
|
# Jinja2 magic: Only run this LVM task if the target string starts with '/dev/'
|
|
when: item.targets[inventory_hostname].startswith('/dev/')
|
|
|
|
- name: Ensure LVM Thin Pools exist for raw disks
|
|
community.general.lvol:
|
|
vg: "{{ item.vg_name }}"
|
|
lv: "{{ item.thin_name }}"
|
|
size: "100%FREE"
|
|
opts: "-T -Zn"
|
|
shrink: false
|
|
loop: "{{ linstor_storage_pools }}"
|
|
when: item.targets[inventory_hostname].startswith('/dev/')
|
|
|
|
# ---------------------------------------------------------
|
|
# LINSTOR STORAGE REGISTRATION (Executed ONLY on Node 1)
|
|
# ---------------------------------------------------------
|
|
|
|
- name: Register Storage Pools in LINSTOR
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
|
|
# We use Jinja2 to write a custom bash loop for exactly the nodes in our inventory
|
|
{% for host in groups['proxmox'] %}
|
|
{% set target = item.targets[host] %}
|
|
{% set lvm_path = (item.vg_name + '/' + item.thin_name) if target.startswith('/dev/') else target %}
|
|
|
|
if ! linstor storage-pool list | grep -q " {{ host }} .* {{ item.pool_name }} "; then
|
|
linstor storage-pool create lvmthin "{{ host }}" "{{ item.pool_name }}" "{{ lvm_path }}" > /dev/null
|
|
echo "changed"
|
|
fi
|
|
{% endfor %}
|
|
args:
|
|
executable: /bin/bash
|
|
register: linstor_storage_pool_create
|
|
changed_when: "'changed' in linstor_storage_pool_create.stdout"
|
|
loop: "{{ linstor_storage_pools }}"
|
|
when: inventory_hostname == groups['proxmox'][0]
|
|
|
|
- name: Create Resource Groups and Volume Groups
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
if ! linstor resource-group list | grep -q " {{ item.rg_name }} "; then
|
|
linstor resource-group create "{{ item.rg_name }}" --storage-pool "{{ item.pool_name }}" --place-count 3 > /dev/null
|
|
linstor volume-group create "{{ item.rg_name }}" > /dev/null
|
|
echo "changed"
|
|
fi
|
|
args:
|
|
executable: /bin/bash
|
|
register: linstor_storage_rg_create
|
|
changed_when: "'changed' in linstor_storage_rg_create.stdout"
|
|
loop: "{{ linstor_storage_pools }}"
|
|
when: inventory_hostname == groups['proxmox'][0]
|