From 251a8f7f649321dd42b56081d3e4dbed254201a8 Mon Sep 17 00:00:00 2001 From: Francesco Zimbolo Date: Thu, 23 Apr 2026 08:18:49 +0000 Subject: [PATCH] Added support for single-node setups --- ansible/deploy.yml | 123 +++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 55 deletions(-) diff --git a/ansible/deploy.yml b/ansible/deploy.yml index 52e4e49..6538a94 100644 --- a/ansible/deploy.yml +++ b/ansible/deploy.yml @@ -6,6 +6,10 @@ any_errors_fatal: true 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) }}" master_corosync_ip: "{{ hostvars[groups['proxmox'][0]]['priv_ip'] | default(hostvars[groups['proxmox'][0]]['ansible_host']) }}" is_master: "{{ inventory_hostname == groups['proxmox'][0] }}" @@ -33,10 +37,12 @@ state: "{{ 'absent' if pve_enterprise_key | length > 0 else 'present' }}" filename: pve-no-subscription - - name: Add Linstor Repositories + - name: Add Linstor Repositories (Skipped in Single Node) ansible.builtin.include_role: name: linstor_repo - when: deploy_linstor | bool + when: + - deploy_linstor | bool + - not is_single_node | bool # ========================================== # PHASE 2: UPDATES & NAG REMOVAL @@ -55,10 +61,12 @@ replace: "void({ //\\1" notify: Restart pveproxy - - name: Install Linstor Packages + - name: Install Linstor Packages (Skipped in Single Node) ansible.builtin.include_role: name: linstor_install - when: deploy_linstor | bool + when: + - deploy_linstor | bool + - not is_single_node | bool - name: Reboot if kernel was updated ansible.builtin.reboot: @@ -68,67 +76,72 @@ # ========================================== # PHASE 3: PROXMOX CLUSTERING # ========================================== - - name: Ensure SSH keypair exists for root - ansible.builtin.user: - name: root - generate_ssh_key: yes - ssh_key_bits: 4096 + - name: PROXMOX CLUSTERING (Skipped in Single Node Mode) + when: not is_single_node | bool + block: + - name: Ensure SSH keypair exists for root + ansible.builtin.user: + name: root + generate_ssh_key: yes + ssh_key_bits: 4096 - - name: Fetch public SSH keys from all nodes - ansible.builtin.slurp: - src: /root/.ssh/id_rsa.pub - register: ssh_pub_keys + - name: Fetch public SSH keys from all nodes + ansible.builtin.slurp: + src: /root/.ssh/id_rsa.pub + register: ssh_pub_keys - - name: Distribute SSH keys to build full-mesh trust - ansible.posix.authorized_key: - user: root - key: "{{ hostvars[item]['ssh_pub_keys']['content'] | b64decode }}" - state: present - loop: "{{ ansible_play_hosts }}" + - name: Distribute SSH keys to build full-mesh trust + ansible.posix.authorized_key: + user: root + key: "{{ hostvars[item]['ssh_pub_keys']['content'] | b64decode }}" + state: present + loop: "{{ ansible_play_hosts }}" - - name: Automatically accept host keys for cluster subnets - ansible.builtin.blockinfile: - path: /root/.ssh/config - create: yes - mode: '0600' - block: | - Host {{ master_corosync_ip | regex_replace('\.[0-9]+$', '.*') }} {{ hostvars[groups['proxmox'][0]]['ansible_host'] | regex_replace('\.[0-9]+$', '.*') }} - StrictHostKeyChecking no - UserKnownHostsFile=/dev/null + - name: Automatically accept host keys for cluster subnets + ansible.builtin.blockinfile: + path: /root/.ssh/config + create: yes + mode: '0600' + block: | + Host {{ master_corosync_ip | regex_replace('\.[0-9]+$', '.*') }} {{ hostvars[groups['proxmox'][0]]['ansible_host'] | regex_replace('\.[0-9]+$', '.*') }} + StrictHostKeyChecking no + UserKnownHostsFile=/dev/null - - name: Check current Proxmox cluster status - ansible.builtin.command: pvecm status - register: pvecm_status - ignore_errors: yes - changed_when: false + - name: Check current Proxmox cluster status + ansible.builtin.command: pvecm status + register: pvecm_status + ignore_errors: yes + changed_when: false - - name: Initialize the Proxmox Cluster (Master Node) - ansible.builtin.command: pvecm create {{ pve_cluster_name }} --link0 {{ corosync_ip }} - when: - - pvecm_status.rc != 0 - - is_master | bool + - name: Initialize the Proxmox Cluster (Master Node) + ansible.builtin.command: pvecm create {{ pve_cluster_name }} --link0 {{ corosync_ip }} + when: + - pvecm_status.rc != 0 + - is_master | bool - - name: Wait for Corosync to stabilize - ansible.builtin.pause: - seconds: 10 - when: - - pvecm_status.rc != 0 - - is_master | bool + - name: Wait for Corosync to stabilize + ansible.builtin.pause: + seconds: 10 + when: + - pvecm_status.rc != 0 + - is_master | bool - - name: Join the Proxmox Cluster (Worker Nodes) - ansible.builtin.command: > - pvecm add {{ master_corosync_ip }} --link0 {{ corosync_ip }} --use_ssh yes - when: - - pvecm_status.rc != 0 - - not is_master | bool - async: 60 - poll: 10 + - name: Join the Proxmox Cluster (Worker Nodes) + ansible.builtin.command: > + pvecm add {{ master_corosync_ip }} --link0 {{ corosync_ip }} --use_ssh yes + when: + - pvecm_status.rc != 0 + - not is_master | bool + async: 60 + poll: 10 # ========================================== # PHASE 4: LINSTOR CONFIGURATION # ========================================== - - name: Configure Linstor (Skipped if deploy_linstor=false) - when: deploy_linstor | bool + - name: LINSTOR CONFIGURATION (Skipped if deploy_linstor=false or Single Node) + when: + - deploy_linstor | bool + - not is_single_node | bool block: - name: Configure Linstor Cluster ansible.builtin.include_role: @@ -150,4 +163,4 @@ - name: Restart pveproxy ansible.builtin.service: name: pveproxy - state: restarted \ No newline at end of file + state: restarted