From c6fe8607f5184bca98d2d3fd2c3ac62c080187fc Mon Sep 17 00:00:00 2001 From: Radar231 Date: Sat, 7 Jan 2023 20:51:52 +0000 Subject: [PATCH] renamed inventory file restructured to support more generic k3s single host or cluster deployment --- k3s_inventory.yml => ex-inv_k3s.yml | 15 ------------- k3s.yml | 33 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 30 deletions(-) rename k3s_inventory.yml => ex-inv_k3s.yml (54%) diff --git a/k3s_inventory.yml b/ex-inv_k3s.yml similarity index 54% rename from k3s_inventory.yml rename to ex-inv_k3s.yml index ae4bbcb..672b16e 100644 --- a/k3s_inventory.yml +++ b/ex-inv_k3s.yml @@ -13,20 +13,5 @@ all: ansible_host: 192.168.122.232 node3: ansible_host: 192.168.122.233 - children: - master: - hosts: - node1: - workers: - hosts: - node2: - node3: - # Global variables - vars: - # Switch to control whether we are creating a cluster, or just - # deploying to a single host - do_cluster: true - # Minimum hosts for our cluster - minhosts: "3" # EOF diff --git a/k3s.yml b/k3s.yml index 496fb64..f660a89 100644 --- a/k3s.yml +++ b/k3s.yml @@ -3,29 +3,29 @@ # # This is the top level playbook for the 'k3s' role. # -# This role will install a k3s cluster to three or more target hosts. +# This playbook will install k3s to one or more hosts. If there are multiple +# hosts the first inventory host will be the master node, and all others will +# be worker nodes. # -# This role requires at least three target hosts, previously deployed. Each -# host should have at least 4GB of RAM and at least a 20GB disk. +# This playbook will only setup simple clusters with a single master node. To +# setup an HA cluster with multiple master nodes, please refer to the following +# URL and perform the cluster installation manually. +# +# * https://docs.k3s.io/installation/ha-embedded +# +# Each host should have at least 4GB of RAM and at least a 20GB disk. # # It is also assumed that the user running the playbook has SSH key access # set up for the root user on the target hosts. # -# NOTE: If you are installing in a proxied environment, make sure that you -# have either 'HTTP_PROXY' or 'HTTPS_PROXY' (case is not important) -# defined in your env variables (usually via ~/.bashrc). In addition -# to that, you also need to have 'NO_PROXY' (again, case is not -# important) also defined. This is where the k3s installer will -# retrieve the relevant proxy configuration values. -# ########################################################################### # # This playbook can be run using the following command line; # -# ansible-playbook -i -e "username=" k3s.yml +# ansible-playbook -i -e "k3s_user=" k3s.yml # # ie, -# ansible-playbook -i k3s_inventory.yml -e "username=someuser" k3s.yml +# ansible-playbook -i ex-inv_k3s.yml -e "k3s_user=someuser" k3s.yml # ########################################################################### @@ -37,12 +37,15 @@ - role: k3s vars: # Calculate the number of target hosts - numhosts: "{{ groups['all'] | length }}" + numhosts: "{{ ansible_play_hosts | length }}" + master_host: "{{ ansible_play_hosts[0] }}" + master_ip: "{{ hostvars[master_host].ansible_host }}" + # Set the following variable as required # ie, - # username: someuser + # k3s_user: someuser # # Default is to apply the playbook against the root user - username: "root" + k3s_user: "root" # EOF