diff --git a/README.md b/README.md index 70d599c..f791a65 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index 1a199b6..dd1baa5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/molecule/default/playbook-standalone.yml b/molecule/default/playbook-standalone.yml new file mode 100644 index 0000000..a7ed01f --- /dev/null +++ b/molecule/default/playbook-standalone.yml @@ -0,0 +1,9 @@ +--- +- name: Converge + hosts: all + become: true + vars: + molecule_is_test: true + k3s_build_cluster: false + roles: + - role: xanmanning.k3s diff --git a/molecule/highavailability/playbook-dqlite.yml b/molecule/highavailability/playbook-dqlite.yml index 786caf7..4d41510 100644 --- a/molecule/highavailability/playbook-dqlite.yml +++ b/molecule/highavailability/playbook-dqlite.yml @@ -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 diff --git a/tasks/build/preconfigure-k3s.yml b/tasks/build/preconfigure-k3s.yml index b83b8cc..9471b16 100644 --- a/tasks/build/preconfigure-k3s.yml +++ b/tasks/build/preconfigure-k3s.yml @@ -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 diff --git a/tasks/state-installed.yml b/tasks/state-installed.yml index 0747236..011e520 100644 --- a/tasks/state-installed.yml +++ b/tasks/state-installed.yml @@ -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 diff --git a/tasks/validate/main.yml b/tasks/validate/main.yml index ce6216a..ac0fe9f 100644 --- a/tasks/validate/main.yml +++ b/tasks/validate/main.yml @@ -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