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

Init cluster error on master role #183

Closed nawarajshahi closed 1 year ago

nawarajshahi commented 1 year ago

hey @timothystewart6, I am currently trying to deploy this to my ubuntu 22.04 vms and I keep getting the undefined variable errors.

Expected Behavior

master node role should copy the templates to destination as noted on the roles

Current Behavior

This should copy the templates to destination as noted on the roles but it fails to template the files under templates folder for master role.

error

TASK [k3s/master : Init cluster inside the transient k3s-init service] **************************************************************************************************************************
fatal: [192.168.33.119]: FAILED! => 
  msg: |-
    The task includes an option with an undefined variable. The error was: {% if groups['master'] | length > 1 %}
      {% if ansible_hostname == hostvars[groups['master'][0]]['ansible_hostname'] %}
        --cluster-init
      {% else %}
        --server https://{{ hostvars[groups['master'][0]].k3s_node_ip }}:6443
      {% endif %}
      --token {{ k3s_token }}
    {% endif %} {{ extra_server_args | default('') }}: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'k3s_node_ip'

    The error appears to be in '/home/nabu/repos/projects/k3s-ansible/roles/k3s/master/tasks/main.yml': line 62, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    - name: Init cluster inside the transient k3s-init service
      ^ here
fatal: [192.168.33.120]: FAILED! => 
  msg: |-
    The task includes an option with an undefined variable. The error was: {% if groups['master'] | length > 1 %}
      {% if ansible_hostname == hostvars[groups['master'][0]]['ansible_hostname'] %}
        --cluster-init
      {% else %}
        --server https://{{ hostvars[groups['master'][0]].k3s_node_ip }}:6443
      {% endif %}
      --token {{ k3s_token }}
    {% endif %} {{ extra_server_args | default('') }}: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'k3s_node_ip'

    The error appears to be in '/home/nabu/repos/projects/k3s-ansible/roles/k3s/master/tasks/main.yml': line 62, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    - name: Init cluster inside the transient k3s-init service
      ^ here

Steps to Reproduce

changed all the required lines under hosts.ini and all.yaml

Context (variables)

ubuntu 22.04 running on proxmox vm

Question

Do you have any suggestions for resolving this issue?