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

The task Init cluster inside the transient k3s-init service fails when using wsl to run #354

Closed Squawkykaka closed 1 year ago

Squawkykaka commented 1 year ago

Expected Behavior

I dont really know it just spit out a huge error

Current Behavior

It gets to the task then gives this error:

TASK [k3s_server : Init cluster inside the transient k3s-init service] ***** fatal: [192.168.86.45]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {% if groups[group_name_master | default('master')] | length > 1 %}\n {% if ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname'] %}\n --cluster-init\n {% else %}\n --server https://{{ hostvars[groups[group_name_master | default('master')][0]].k3s_node_ip | split(\",\") | first | ansible.utils.ipwrap }}:6443\n {% endif %}\n --token {{ k3s_token }}\n{% endif %} {{ extra_server_args | default('') }}: {{ extra_args }} {{ '--node-taint node-role.kubernetes.io/master=true:NoSchedule' if k3s_master_taint else '' }} --tls-san {{ apiserver_endpoint }} --disable servicelb --disable traefik: --flannel-iface={{ flannel_iface }} --node-ip={{ k3s_node_ip }}: {{ ansible_facts[flannel_iface][\"ipv4\"][\"address\"] }}: 'dict object' has no attribute 'eth0'\n\nThe error appears to be in '/home/gleask/ansible/k3s-ansible/roles/k3s_server/tasks/main.yml': line 21, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Init cluster inside the transient k3s-init service\n ^ here\n"} fatal: [192.168.86.47]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {% if groups[group_name_master | default('master')] | length > 1 %}\n {% if ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname'] %}\n --cluster-init\n {% else %}\n --server https://{{ hostvars[groups[group_name_master | default('master')][0]].k3s_node_ip | split(\",\") | first | ansible.utils.ipwrap }}:6443\n {% endif %}\n --token {{ k3s_token }}\n{% endif %} {{ extra_server_args | default('') }}: {{ extra_args }} {{ '--node-taint node-role.kubernetes.io/master=true:NoSchedule' if k3s_master_taint else '' }} --tls-san {{ apiserver_endpoint }} --disable servicelb --disable traefik: --flannel-iface={{ flannel_iface }} --node-ip={{ k3s_node_ip }}: {{ ansible_facts[flannel_iface][\"ipv4\"][\"address\"] }}: 'dict object' has no attribute 'eth0'\n\nThe error appears to be in '/home/gleask/ansible/k3s-ansible/roles/k3s_server/tasks/main.yml': line 21, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Init cluster inside the transient k3s-init service\n ^ here\n"} fatal: [192.168.86.46]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {% if groups[group_name_master | default('master')] | length > 1 %}\n {% if ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname'] %}\n --cluster-init\n {% else %}\n --server https://{{ hostvars[groups[group_name_master | default('master')][0]].k3s_node_ip | split(\",\") | first | ansible.utils.ipwrap }}:6443\n {% endif %}\n --token {{ k3s_token }}\n{% endif %} {{ extra_server_args | default('') }}: {{ extra_args }} {{ '--node-taint node-role.kubernetes.io/master=true:NoSchedule' if k3s_master_taint else '' }} --tls-san {{ apiserver_endpoint }} --disable servicelb --disable traefik: --flannel-iface={{ flannel_iface }} --node-ip={{ k3s_node_ip }}: {{ ansible_facts[flannel_iface][\"ipv4\"][\"address\"] }}: 'dict object' has no attribute 'eth0'\n\nThe error appears to be in '/home/gleask/ansible/k3s-ansible/roles/k3s_server/tasks/main.yml': line 21, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Init cluster inside the transient k3s-init service\n ^ here\n"}

PLAY RECAP ***** 192.168.86.43 : ok=12 changed=0 unreachable=0 failed=0 skipped=14 rescued=0 ignored=0 192.168.86.45 : ok=13 changed=0 unreachable=0 failed=1 skipped=22 rescued=0 ignored=0 192.168.86.46 : ok=13 changed=0 unreachable=0 failed=1 skipped=22 rescued=0 ignored=0 192.168.86.47 : ok=19 changed=4 unreachable=0 failed=1 skipped=16 rescued=0 ignored=0

Steps to Reproduce

Run the install script in ubuntu wsl

1. 2. 3. 4.

Context (variables)

Operating system: Windows 11 Home (WSL ubuntu)

Hardware:

Variables Used

all.yml

k3s_version: v1.25.12+k3s1
ansible_user: NA
systemd_dir: /etc/systemd/system

flannel_iface: "eth0"

apiserver_endpoint: "192.168.30.222"

k3s_token: "NA"

extra_server_args: >-
  {{ extra_args }}
  {{ '--node-taint node-role.kubernetes.io/master=true:NoSchedule' if k3s_master_taint else '' }}
  --tls-san {{ apiserver_endpoint }}
  --disable servicelb
  --disable traefik

extra_agent_args: >-
  {{ extra_args }}

kube_vip_tag_version: "v0.5.12"

metal_lb_speaker_tag_version: "v0.13.9"
metal_lb_controller_tag_version: "v0.13.9"

metal_lb_ip_range: "192.168.30.80-192.168.30.90" # The defaults

Hosts

host.ini

[master]
IP.ADDRESS.ONE
IP.ADDRESS.TWO
IP.ADDRESS.THREE

[node]
IP.ADDRESS.FOUR

[k3s_cluster:children]
master
node

Possible Solution

Jimikephart commented 1 year ago

I have the same issue. I’m not sure the IP scheme is correct. Like do those ips need to be on the network you have set up or are they built with metallb

xymvl4t3d commented 1 year ago

@Jimikephart The IPs need to be changed with the one according to your network.

@Squawkykaka This is not only happening in WSL, I encountered a similar issue too when trying to set 3 master nodes in hosts.ini. Setting 1 master node works though. 1 task fails for each of the 3 master nodes. Though not exactly the same error, it also had something to do with the "Init cluster inside the transient k3s-init service fails" task.

@timothystewart6 Any ideas?

Jimikephart commented 1 year ago

@xymvl4t3d is it just an ip off my /24 then that doesn’t go to anything? My hardware is 10.10.0.3-10 with me running the commands on 10.10.0.7

xymvl4t3d commented 1 year ago

@Jimikephart yes, unassigned IPs from your network. for e.g.

default: apiserver_endpoint: "192.168.30.222"

yours would be: apiserver_endpoint: "10.10.0.X"

X being an unassigned IP

Squawkykaka commented 1 year ago

@xymvl4t3d oh so my apiserver_endpoint shoul be 192.168.86.222 or something like that as all my ips have 86 in them

Squawkykaka commented 1 year ago

still broken after that and it also seems to be related to:

server_init_args: >- {% if groups[group_name_master | default('master')] | length > 1 %} {% if ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname'] %} --cluster-init {% else %} --server https://{{ hostvars[groups[group_name_master | default('master')][0]].k3s_node_ip | split(",") | first | ansible.utils.ipwrap }}:6443 {% endif %} --token {{ k3s_token }} {% endif %} {{ extra_server_args | default('') }}