PyratLabs / ansible-role-k3s

Ansible role for installing k3s as either a standalone server or HA cluster.
BSD 3-Clause "New" or "Revised" License
640 stars 135 forks source link

Check that cluster-token exists: 'dict object' has no attribute 'stat' #156

Closed kenorb closed 3 years ago

kenorb commented 3 years ago

Summary

When I run playbook on the existing configured cluster, I've got the fatal error:

FAILED! => {"msg": "The conditional check 'not k3s_check_cluster_token.stat.exists' failed. The error was: error while evaluating conditional (not k3s_check_cluster_token.stat.exists): 'dict object' has no attribute 'stat'"}

Issue Type

Controller Environment and Configuration

$ ansible --version
ansible [core 2.11.5] 
$ ansible-galaxy list
- xanmanning.k3s, v2.11.0

Steps to Reproduce

---
- hosts: vm01
  roles:
    - role: xanmanning.k3s
      vars:
        k3s_become_for_install_dir: true
        k3s_become_for_usr_local_bin: true
        k3s_server:
          write-kubeconfig-mode: 0640
        k3s_state: installed

Expected Result

Check that cluster-token exists

Should run without errors.

Actual Result

$ ansible-playbook -i hostfile k3s-setup.yml -vv
...
TASK [xanmanning.k3s : Check that the initial control plane server is available to accept connections] *************************************************************************************************************************************************************
task path: ~/.ansible/roles/xanmanning.k3s/tasks/validate/configuration/cluster-init.yml:3
ok: [vm01] => {"changed": false, "elapsed": 5, "match_groupdict": {}, "match_groups": [], "path": null, "port": 6443, "search_regex": null, "state": "started"}

TASK [xanmanning.k3s : Check that cluster-token exists] ************************************************************************************************************************************************************************************************************
task path: ~/.ansible/roles/xanmanning.k3s/tasks/validate/configuration/cluster-init.yml:11
fatal: [vm01]: FAILED! => {"msg": "The conditional check 'not k3s_check_cluster_token.stat.exists' failed. The error was: error while evaluating conditional (not k3s_check_cluster_token.stat.exists): 'dict object' has no attribute 'stat'"}
xanmanning commented 3 years ago

https://asciinema.org/a/cwHkB4NvpOCK1smgwQano1rqO

Perhaps try this for a playbook?

---

- hosts: vm01
  become: true
  roles:
    - role: xanmanning.k3s
      vars:
        k3s_become_for_all: true
        k3s_server:
          write-kubeconfig-mode: '0640'
        k3s_state: installed

issue-156.tar.gz

kenorb commented 3 years ago

Your config seems to work fine. After adding k3s_become_for_all: true to my config, it works fine.

But after re-running it with:

        k3s_become_for_directory_creation: true
        k3s_become_for_install_dir: true
        k3s_become_for_systemd: true
        k3s_become_for_uninstall: true
        k3s_become_for_usr_local_bin: true

instead of k3s_become_for_all, it generates the same error.

If I want to split become, which param is missing in above list, or it's a bug?

kenorb commented 3 years ago
k3s_become_for_kubectl: true

was missing, I assume it's expected behaviour.