Added support for single-node setups

This commit is contained in:
Francesco Zimbolo
2026-04-23 08:18:49 +00:00
parent 861a468fc7
commit 251a8f7f64

View File

@@ -6,6 +6,10 @@
any_errors_fatal: true any_errors_fatal: true
vars: vars:
# Dynamically detect if we are in Single-Node or Cluster mode
is_single_node: "{{ groups['proxmox'] | length == 1 }}"
# Existing clustering variables
corosync_ip: "{{ priv_ip | default(ansible_host) }}" corosync_ip: "{{ priv_ip | default(ansible_host) }}"
master_corosync_ip: "{{ hostvars[groups['proxmox'][0]]['priv_ip'] | default(hostvars[groups['proxmox'][0]]['ansible_host']) }}" master_corosync_ip: "{{ hostvars[groups['proxmox'][0]]['priv_ip'] | default(hostvars[groups['proxmox'][0]]['ansible_host']) }}"
is_master: "{{ inventory_hostname == groups['proxmox'][0] }}" is_master: "{{ inventory_hostname == groups['proxmox'][0] }}"
@@ -33,10 +37,12 @@
state: "{{ 'absent' if pve_enterprise_key | length > 0 else 'present' }}" state: "{{ 'absent' if pve_enterprise_key | length > 0 else 'present' }}"
filename: pve-no-subscription filename: pve-no-subscription
- name: Add Linstor Repositories - name: Add Linstor Repositories (Skipped in Single Node)
ansible.builtin.include_role: ansible.builtin.include_role:
name: linstor_repo name: linstor_repo
when: deploy_linstor | bool when:
- deploy_linstor | bool
- not is_single_node | bool
# ========================================== # ==========================================
# PHASE 2: UPDATES & NAG REMOVAL # PHASE 2: UPDATES & NAG REMOVAL
@@ -55,10 +61,12 @@
replace: "void({ //\\1" replace: "void({ //\\1"
notify: Restart pveproxy notify: Restart pveproxy
- name: Install Linstor Packages - name: Install Linstor Packages (Skipped in Single Node)
ansible.builtin.include_role: ansible.builtin.include_role:
name: linstor_install name: linstor_install
when: deploy_linstor | bool when:
- deploy_linstor | bool
- not is_single_node | bool
- name: Reboot if kernel was updated - name: Reboot if kernel was updated
ansible.builtin.reboot: ansible.builtin.reboot:
@@ -68,67 +76,72 @@
# ========================================== # ==========================================
# PHASE 3: PROXMOX CLUSTERING # PHASE 3: PROXMOX CLUSTERING
# ========================================== # ==========================================
- name: Ensure SSH keypair exists for root - name: PROXMOX CLUSTERING (Skipped in Single Node Mode)
ansible.builtin.user: when: not is_single_node | bool
name: root block:
generate_ssh_key: yes - name: Ensure SSH keypair exists for root
ssh_key_bits: 4096 ansible.builtin.user:
name: root
generate_ssh_key: yes
ssh_key_bits: 4096
- name: Fetch public SSH keys from all nodes - name: Fetch public SSH keys from all nodes
ansible.builtin.slurp: ansible.builtin.slurp:
src: /root/.ssh/id_rsa.pub src: /root/.ssh/id_rsa.pub
register: ssh_pub_keys register: ssh_pub_keys
- name: Distribute SSH keys to build full-mesh trust - name: Distribute SSH keys to build full-mesh trust
ansible.posix.authorized_key: ansible.posix.authorized_key:
user: root user: root
key: "{{ hostvars[item]['ssh_pub_keys']['content'] | b64decode }}" key: "{{ hostvars[item]['ssh_pub_keys']['content'] | b64decode }}"
state: present state: present
loop: "{{ ansible_play_hosts }}" loop: "{{ ansible_play_hosts }}"
- name: Automatically accept host keys for cluster subnets - name: Automatically accept host keys for cluster subnets
ansible.builtin.blockinfile: ansible.builtin.blockinfile:
path: /root/.ssh/config path: /root/.ssh/config
create: yes create: yes
mode: '0600' mode: '0600'
block: | block: |
Host {{ master_corosync_ip | regex_replace('\.[0-9]+$', '.*') }} {{ hostvars[groups['proxmox'][0]]['ansible_host'] | regex_replace('\.[0-9]+$', '.*') }} Host {{ master_corosync_ip | regex_replace('\.[0-9]+$', '.*') }} {{ hostvars[groups['proxmox'][0]]['ansible_host'] | regex_replace('\.[0-9]+$', '.*') }}
StrictHostKeyChecking no StrictHostKeyChecking no
UserKnownHostsFile=/dev/null UserKnownHostsFile=/dev/null
- name: Check current Proxmox cluster status - name: Check current Proxmox cluster status
ansible.builtin.command: pvecm status ansible.builtin.command: pvecm status
register: pvecm_status register: pvecm_status
ignore_errors: yes ignore_errors: yes
changed_when: false changed_when: false
- name: Initialize the Proxmox Cluster (Master Node) - name: Initialize the Proxmox Cluster (Master Node)
ansible.builtin.command: pvecm create {{ pve_cluster_name }} --link0 {{ corosync_ip }} ansible.builtin.command: pvecm create {{ pve_cluster_name }} --link0 {{ corosync_ip }}
when: when:
- pvecm_status.rc != 0 - pvecm_status.rc != 0
- is_master | bool - is_master | bool
- name: Wait for Corosync to stabilize - name: Wait for Corosync to stabilize
ansible.builtin.pause: ansible.builtin.pause:
seconds: 10 seconds: 10
when: when:
- pvecm_status.rc != 0 - pvecm_status.rc != 0
- is_master | bool - is_master | bool
- name: Join the Proxmox Cluster (Worker Nodes) - name: Join the Proxmox Cluster (Worker Nodes)
ansible.builtin.command: > ansible.builtin.command: >
pvecm add {{ master_corosync_ip }} --link0 {{ corosync_ip }} --use_ssh yes pvecm add {{ master_corosync_ip }} --link0 {{ corosync_ip }} --use_ssh yes
when: when:
- pvecm_status.rc != 0 - pvecm_status.rc != 0
- not is_master | bool - not is_master | bool
async: 60 async: 60
poll: 10 poll: 10
# ========================================== # ==========================================
# PHASE 4: LINSTOR CONFIGURATION # PHASE 4: LINSTOR CONFIGURATION
# ========================================== # ==========================================
- name: Configure Linstor (Skipped if deploy_linstor=false) - name: LINSTOR CONFIGURATION (Skipped if deploy_linstor=false or Single Node)
when: deploy_linstor | bool when:
- deploy_linstor | bool
- not is_single_node | bool
block: block:
- name: Configure Linstor Cluster - name: Configure Linstor Cluster
ansible.builtin.include_role: ansible.builtin.include_role:
@@ -150,4 +163,4 @@
- name: Restart pveproxy - name: Restart pveproxy
ansible.builtin.service: ansible.builtin.service:
name: pveproxy name: pveproxy
state: restarted state: restarted