Refactoring + final touches
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
---
|
||||
# tasks file for linstor_cluster
|
||||
# IMPORTANT: All Linstor node registrations use ansible_hostname (the real system hostname)
|
||||
# to ensure they match Proxmox node names, which are also derived from the system hostname.
|
||||
# The Ansible inventory_hostname (e.g. "pve1") may differ from the real hostname (e.g. "pve-node-01").
|
||||
|
||||
- name: Safely manage LINSTOR cluster nodes in /etc/hosts
|
||||
ansible.builtin.blockinfile:
|
||||
@@ -8,12 +11,12 @@
|
||||
block: |
|
||||
# Linstor Cluster Nodes (Primary: Private Network)
|
||||
{% for host in groups['proxmox'] %}
|
||||
{{ hostvars[host].priv_ip }} {{ host }}
|
||||
{{ hostvars[host]['priv_ip'] | default(hostvars[host]['ansible_host']) }} {{ hostvars[host]['ansible_facts']['hostname'] }}
|
||||
{% endfor %}
|
||||
|
||||
# Linstor Cluster Nodes (Fallback: Public Network)
|
||||
{% for host in groups['proxmox'] %}
|
||||
{{ hostvars[host].ansible_host }} {{ host }}-public
|
||||
{{ hostvars[host]['ansible_host'] }} {{ hostvars[host]['ansible_facts']['hostname'] }}-public
|
||||
{% endfor %}
|
||||
|
||||
- name: Ensure /etc/linstor directory exists
|
||||
@@ -30,13 +33,17 @@
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# LINSTOR NODE REGISTRATION (Executed ONLY on Node 1)
|
||||
# Uses ansible_hostname (real system hostname) for Linstor node names
|
||||
# to guarantee compatibility with Proxmox node names.
|
||||
# ---------------------------------------------------------
|
||||
|
||||
- name: Register nodes in LINSTOR
|
||||
ansible.builtin.shell: |
|
||||
set -o pipefail
|
||||
if ! linstor node list | grep -q " {{ item }} "; then
|
||||
linstor node create "{{ item }}" "{{ hostvars[item].priv_ip }}" --node-type Combined > /dev/null
|
||||
NODE_NAME="{{ hostvars[item]['ansible_facts']['hostname'] }}"
|
||||
NODE_IP="{{ hostvars[item]['priv_ip'] | default(hostvars[item]['ansible_host']) }}"
|
||||
if ! linstor node list | grep -q " ${NODE_NAME} "; then
|
||||
linstor node create "${NODE_NAME}" "${NODE_IP}" --node-type Combined > /dev/null
|
||||
echo "changed"
|
||||
fi
|
||||
args:
|
||||
@@ -49,8 +56,10 @@
|
||||
- name: Configure Multipath Fallback Interfaces
|
||||
ansible.builtin.shell: |
|
||||
set -o pipefail
|
||||
if ! linstor node interface list "{{ item }}" | grep -q " fallback "; then
|
||||
linstor node interface create "{{ item }}" fallback "{{ hostvars[item].ansible_host }}" > /dev/null
|
||||
NODE_NAME="{{ hostvars[item]['ansible_facts']['hostname'] }}"
|
||||
NODE_PUBLIC_IP="{{ hostvars[item]['ansible_host'] }}"
|
||||
if ! linstor node interface list "${NODE_NAME}" | grep -q " fallback "; then
|
||||
linstor node interface create "${NODE_NAME}" fallback "${NODE_PUBLIC_IP}" > /dev/null
|
||||
echo "changed"
|
||||
fi
|
||||
args:
|
||||
@@ -59,3 +68,22 @@
|
||||
changed_when: "'changed' in linstor_cluster_int_create.stdout"
|
||||
loop: "{{ groups['proxmox'] }}"
|
||||
when: inventory_hostname == groups['proxmox'][0]
|
||||
|
||||
- name: Wait for all Linstor satellite nodes to appear as Online
|
||||
ansible.builtin.shell: |
|
||||
set -o pipefail
|
||||
if linstor node list | sed 's/\x1b\[[0-9;]*m//g' | grep " {{ hostvars[item]['ansible_facts']['hostname'] }} " | grep -q "Online"; then
|
||||
echo "online"
|
||||
else
|
||||
echo "not_ready"
|
||||
exit 1
|
||||
fi
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: linstor_cluster_node_status
|
||||
until: "'online' in linstor_cluster_node_status.stdout"
|
||||
retries: 12
|
||||
delay: 10
|
||||
changed_when: false
|
||||
loop: "{{ groups['proxmox'] }}"
|
||||
when: inventory_hostname == groups['proxmox'][0]
|
||||
|
||||
Reference in New Issue
Block a user