Skip to content

Commit

Permalink
Added instructions for clustering.
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmertr committed Jun 29, 2020
1 parent 11a627f commit 266ad69
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
72 changes: 72 additions & 0 deletions 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
30 changes: 30 additions & 0 deletions README.md
Expand Up @@ -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)

Expand Down Expand Up @@ -93,6 +94,35 @@ Now that Proxmox has been installed, it's time to set up a user account for Ansi

<hr>

### 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
```

<hr>

### 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.
Expand Down

0 comments on commit 266ad69

Please sign in to comment.