Added option to provision multiple standalone k3s

Fixes #21
This commit is contained in:
Xan Manning 2020-05-16 20:18:10 +01:00
parent 9b8cf85489
commit aa1a0a9620
7 changed files with 38 additions and 4 deletions

View File

@ -47,6 +47,7 @@ consistency.
|----------------------------------|-------------------------------------------------------------------------------------|-----------------------------------------|
| `k3s_cluster_state` | State of cluster: installed, started, stopped, restarted, downloaded, uninstalled. | installed |
| `k3s_release_version` | Use a specific version of k3s, eg. `v0.2.0`. Specify `false` for latest. | `false` |
| `k3s_build_cluster` | When multiple `play_hosts` are available, attempt to cluster. Read notes below. | `true` |
| `k3s_github_url` | Set the GitHub URL to install k3s from. | https://github.com/rancher/k3s |
| `k3s_install_dir` | Installation directory for k3s. | `/usr/local/bin` |
| `k3s_server_manifests_dir` | Path for place the `k3s_server_manifests_templates`. | `/var/lib/rancher/k3s/server/manifests` |
@ -96,6 +97,22 @@ ensure this is set in your Ansible configuration, eg:
k3s_release_version: v0.2.0
```
#### Important note about `k3s_build_cluster`
If you set `k3s_build_cluster` to `false`, this role will install each play
host as a standalone node. An example of when you might be building a large
number of IoT devices running K3s. Below is a hypothetical situation where we
are to deploy 25 Rasberry Pi devices, each a standalone system and not
a cluster of 25 nodes. To do this we'd use a playbook similar to the below:
```yaml
- hosts: k3s_nodes # eg. 25 RPi's defined in our inventory.
vars:
k3s_build_cluster: false
roles:
- xanmanning.k3s
```
#### Important note about `k3s_non_root`
To install k3s as non root you must not use `become: true`. The intention of

View File

@ -8,6 +8,11 @@ k3s_cluster_state: installed
# k3s_release_version: v0.1.0
k3s_release_version: false
# When multiple play_hosts are present, attempt to cluster the nodes.
# Using false will create multiple standalone nodes.
# (default: true)
k3s_build_cluster: true
# URL for GitHub project
k3s_github_url: https://github.com/rancher/k3s

View File

@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
become: true
vars:
molecule_is_test: true
k3s_build_cluster: false
roles:
- role: xanmanning.k3s

View File

@ -5,7 +5,6 @@
vars:
molecule_is_test: true
k3s_dqlite_datastore: true
k3s_secrets_encryption: true
k3s_use_experimental: true
pre_tasks:
- name: Set each node to be a control node

View File

@ -2,21 +2,22 @@
- name: Ensure k3s control node fact is set
set_fact:
k3s_control_node: false
k3s_control_node: "{{ 'false' if k3s_build_cluster else 'true' }}"
when: k3s_control_node is not defined
- name: Ensure k3s master control node fact is set
set_fact:
k3s_primary_control_node: false
k3s_primary_control_node: "{{ 'false' if k3s_build_cluster else 'true' }}"
when: k3s_primary_control_node is not defined
- name: Ensure a k3s control node is defined if none are found in play_hosts
block:
- name: Set control host
- name: Set the control host
set_fact:
k3s_control_node: true
when: inventory_hostname == play_hosts[0]
when: true not in (hostvars | json_query('*.k3s_control_node'))
and k3s_build_cluster is defined and k3s_build_cluster
- name: Ensure a count of control masters is generated
set_fact:
@ -29,3 +30,4 @@
k3s_primary_control_node: true
when: k3s_controller_count | length > 1
and inventory_hostname == k3s_controller_count[0]
and k3s_build_cluster is defined and k3s_build_cluster

View File

@ -39,3 +39,4 @@
- import_tasks: build/configure-k3s-cluster.yml
when: play_hosts | length > 1
and k3s_build_cluster is defined and k3s_build_cluster

View File

@ -5,3 +5,4 @@
- import_tasks: check-unsupported-rootless.yml
when: k3s_non_root is defined and k3s_non_root
- import_tasks: check-master-count.yml
when: k3s_build_cluster is defined and k3s_build_cluster