techno-tim / k3s-ansible

The easiest way to bootstrap a self-hosted High Availability Kubernetes cluster. A fully automated HA k3s etcd install with kube-vip, MetalLB, and more. Build. Destroy. Repeat.
https://technotim.live/posts/k3s-etcd-ansible/
Apache License 2.0
2.41k stars 1.05k forks source link

allow not specifying master inventory #98

Closed cheddarwhizzy closed 2 years ago

cheddarwhizzy commented 2 years ago

Proposed Changes

In a scenario where you add nodes/agents in separate runs of Ansible, such as:

Cloud - master(s)/control plane

[master]
host1
host2
host3

[node]

[k3s_cluster:children]
master
node

On-Prem - node(s)/agent

[node]
192.168.64.2

[k3s_cluster:children]
master
node

The "On-Prem"/node-only inventory currently fails. Weird because I thought default was sort of a try/catch answer for Jinja.

Error without [master] defined in inventory:

TASK [k3s/node : Copy K3s service file] ************************************************************************************
Wednesday 21 September 2022  23:48:38 -0500 (0:00:01.121)       0:00:07.521 ***
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'master'
fatal: [192.168.64.2]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'master'"}

Error with no hosts under [master] inventory:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: list object has no element 0
fatal: [192.168.64.2]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: list object has no element 0"}

Checklist

timothystewart6 commented 2 years ago

I am not sure about this. I think you can just rerun the playbook on an existing cluster and it will add the new nodes. I would think you would want your host.ini file to specify your desired state, not just the nodes you want to add.

timothystewart6 commented 2 years ago

This is failing tests and while we might want to support adding nodes using this playbook, I am not too sure about the approach. See https://github.com/techno-tim/k3s-ansible/pull/98#issuecomment-1256853034 I think we'll need to think this through and also agree that this is something we want to add. I've added https://github.com/techno-tim/k3s-ansible/issues/107 to discuss.