122 lines
4.7 KiB
YAML
122 lines
4.7 KiB
YAML
---
|
|
# tasks file for linstor_storage
|
|
# NOTE: linstor_storage_pools[].targets keys are Ansible inventory_hostname values.
|
|
# All Linstor registrations use ansible_hostname (real system hostname) instead,
|
|
# to match Proxmox node names. The mapping is done per-host at registration time.
|
|
|
|
- name: Configure LVM global_filter for DRBD safely
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/lvm/lvm.conf
|
|
insertafter: '^[ \t]*devices[ \t]*\{'
|
|
regexp: '^[ \t]*global_filter[ \t]*='
|
|
line: ' global_filter = [ "r|^/dev/drbd|", "r|^/dev/mapper/[lL]instor|" ]'
|
|
state: present
|
|
|
|
- name: Remove duplicate global_filter entries from lvm.conf
|
|
ansible.builtin.shell: |
|
|
count=$(grep -c '^[[:space:]]*global_filter[[:space:]]*=' /etc/lvm/lvm.conf)
|
|
if [ "$count" -gt 1 ]; then
|
|
awk '/^[[:space:]]*global_filter[[:space:]]*=/{if(++n>1)next}1' /etc/lvm/lvm.conf > /tmp/lvm.conf.dedup
|
|
mv /tmp/lvm.conf.dedup /etc/lvm/lvm.conf
|
|
echo "changed: removed $((count - 1)) duplicate(s)"
|
|
fi
|
|
args:
|
|
executable: /bin/bash
|
|
register: lvm_dedup_result
|
|
changed_when: "'changed' in lvm_dedup_result.stdout"
|
|
|
|
- name: Wipe existing signatures and partition tables from raw disks
|
|
ansible.builtin.shell: |
|
|
DEV="{{ item.targets[inventory_hostname] }}"
|
|
VG="{{ item.vg_name }}"
|
|
|
|
# Deactivate VG properly if LVM still knows about it
|
|
vgchange -an "$VG" 2>/dev/null || true
|
|
|
|
# Forcibly remove any stale dm-mapper devices for this VG (handles the case
|
|
# where the VG metadata was already wiped but kernel devices are still active)
|
|
dmsetup ls 2>/dev/null \
|
|
| awk -v vg="$VG" 'index($1, vg"-") == 1 { print $1 }' \
|
|
| xargs -r dmsetup remove --force 2>/dev/null || true
|
|
|
|
wipefs -a "$DEV"
|
|
sgdisk --zap-all "$DEV"
|
|
partprobe "$DEV" 2>/dev/null || true
|
|
args:
|
|
executable: /bin/bash
|
|
changed_when: true
|
|
loop: "{{ linstor_storage_pools }}"
|
|
when:
|
|
- wipe_linstor_disks | default(false) | bool
|
|
- item.targets[inventory_hostname] is defined
|
|
- item.targets[inventory_hostname].startswith('/dev/')
|
|
|
|
- name: Ensure Volume Groups exist for raw disks
|
|
community.general.lvg:
|
|
vg: "{{ item.vg_name }}"
|
|
pvs: "{{ item.targets[inventory_hostname] }}"
|
|
pv_options: "{{ '--force --force' if wipe_linstor_disks | default(false) | bool else '--force' }}"
|
|
loop: "{{ linstor_storage_pools }}"
|
|
# Only run for pools that target this node AND use a raw block device
|
|
when:
|
|
- item.targets[inventory_hostname] is defined
|
|
- 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] is defined
|
|
- item.targets[inventory_hostname].startswith('/dev/')
|
|
|
|
# ---------------------------------------------------------
|
|
# LINSTOR STORAGE REGISTRATION (Executed ONLY on Node 1)
|
|
# Uses ansible_hostname (real system hostname) for Linstor node names
|
|
# ---------------------------------------------------------
|
|
|
|
- name: Register Storage Pools in LINSTOR
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
|
|
# Iterate over all inventory hosts for this pool.
|
|
# Use ansible_hostname (real system hostname) as Linstor node name.
|
|
{% for host in groups['proxmox'] %}
|
|
{% if item.targets[host] is defined %}
|
|
{% set target = item.targets[host] %}
|
|
{% set lvm_path = (item.vg_name + '/' + item.thin_name) if target.startswith('/dev/') else target %}
|
|
NODE_NAME="{{ hostvars[host]['ansible_facts']['hostname'] }}"
|
|
if ! linstor storage-pool list | grep -q " ${NODE_NAME} .* {{ item.pool_name }} "; then
|
|
linstor storage-pool create lvmthin "${NODE_NAME}" "{{ item.pool_name }}" "{{ lvm_path }}" > /dev/null
|
|
echo "changed"
|
|
fi
|
|
{% endif %}
|
|
{% 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 {{ groups['proxmox'] | length }} > /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]
|