From 266ad694672a951d102306b20ddc5dc705f3a915 Mon Sep 17 00:00:00 2001 From: TJ Zimmerman Date: Sun, 28 Jun 2020 17:22:01 -0700 Subject: [PATCH] Added instructions for clustering. --- Ansible/configure_cluster.yml | 72 +++++++++++++++++++++++++++++++++++ README.md | 30 +++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 Ansible/configure_cluster.yml diff --git a/Ansible/configure_cluster.yml b/Ansible/configure_cluster.yml new file mode 100644 index 0000000..0a18a8e --- /dev/null +++ b/Ansible/configure_cluster.yml @@ -0,0 +1,72 @@ +--- +- hosts: localhost + gather_facts: False + vars: + MASTER_PASSWORD: "{{ lookup('env', 'TKS_BP_V_PROXMOX_MASTER_PASSWORD') }}" + tasks: + # This check should probably be removed. Single node clusters are a valid thing in Proxmox. + - fail: + msg: "The `nodes` group in Ansible inventory is misconfigured. At least one node is required." + when: > + groups["nodes"] is not defined or + groups["nodes"] | length < 1 + + - fail: + msg: "Master group in Ansible inventory misconfigured. Only one host supported." + when: > + groups["master"] is not defined or + groups["master"] | length > 1 + + - fail: + msg: "Please export TKS_BP_V_PROXMOX_MASTER_PASSWORD environment variable" + when: MASTER_PASSWORD == "" + no_log: true # Prevents password from being logged + + +- hosts: master + become: true + gather_facts: False + vars: + CLUSTER_NAME: "{{ lookup('env', 'TKS_BP_V_PROXMOX_CLUSTER_NAME') | default('TKS') }}" + tasks: + - name: Evaluating whether or not the node is already a member of a cluster. + command: pvecm status + register: cluster_result + ignore_errors: yes + + - name: Forming a cluster on the master + command: pvecm create {{ CLUSTER_NAME }} + when: cluster_result.rc == 2 + + +- hosts: master # Gather facts about master group. +- hosts: nodes + become: true + gather_facts: False + vars: + CLUSTER_NAME: "{{ lookup('env', 'TKS_BP_V_PROXMOX_CLUSTER_NAME') | default('TKS') }}" + MASTER_PASSWORD: "{{ lookup('env', 'TKS_BP_V_PROXMOX_MASTER_PASSWORD') }}" + tasks: + - name: Evaluating whether or not the node is already a member of a cluster. + command: pvecm status + register: cluster_result + ignore_errors: yes + + - name: Joining the node to the cluster + when: cluster_result.rc == 2 + block: + - apt: + name: python-pip + when: cluster_result.rc == 2 + + - pip: + name: pexpect + + - expect: + command: pvecm add "{{ hostvars[item]['ansible_fqdn'] }}" + responses: + "Please enter superuser*": "{{ MASTER_PASSWORD }}" + "Are you sure*": "yes" + with_items: + - "{{ groups['master'][0] }}" + no_log: true # Prevents password from being logged diff --git a/README.md b/README.md index 01487e5..557c300 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ * [Instructions](#Instructions) * [Install Proxmox VE](#Install-Proxmox-VE) * [Create User Account](#Create-User-Account) + * [Configure Clustering](#Configure-Clustering) * [Configure Storage](#Configure-Storage) * [Configure Proxmox](#Configure-Proxmox) @@ -93,6 +94,35 @@ Now that Proxmox has been installed, it's time to set up a user account for Ansi
+### Configure Clustering + +Your environment may or may not include multiple physical nodes. as a result, this step is **optional**. In order to form a cluster, you must have at least one master and node present in your inventory file under the groups `master` and `nodes`. Furthermore, only a single master can be in your inventory. Lastly, as a limitation invoked by Proxmox, your node can not have any workloads currently running on it. + +Configure your shell so that it does not commit entries to history that start with a whitespace. Then export the required environment variables and the Ansible Playbook. + +```bash +export HISTCONTROL=ignoreboth +export TKS_BP_V_PROXMOX_CLUSTER_NAME=TKS + export TKS_BP_V_PROXMOX_MASTER_PASSWORD=YOURPASSWORD + +ansible-playbook -i inventory.yml ../TKS-Bootstrap_Proxmox/Ansible/configure_cluster.yml +unset $TKS_BP_V_PROXMOX_MASTER_PASSWORD +``` + +Should something go wrong, or you wish you undo your clustering, you can do so with the following commands: + +```bash +systemctl stop pve-cluster +systemctl stop corosync +pmxcfs -l +rm /etc/pve/corosync.conf +rm /etc/corosync/* +killall pmxcfs +systemctl start pve-cluster +``` + +
+ ### Configure Storage Storage is a delicate component of any environment and there is a larger risk for disaster when applying automation to it as a result. Further complicating this, is that storage is configured differently in almost every environment. As a result, I have decided to leave this portion of TKS as a manual process.