Ansible shell 模块找不到 kubectl

Ansible shell 模块找不到 kubectl

从服务器上的 CLI 运行命令非常完美,但从剧本中使用 Ansible shell 模块运行失败,并显示:

致命:[localhost]:失败! => {“changed”: true,“msg”: “非零返回码”,“rc”: 127,“stderr”: “/bin/sh: kubectl: 未找到命令\n”,“stderr_lines”: [“/bin/sh: kubectl: 未找到命令”],“stdout”: “”,“stdout_lines”: []}

剧本任务:

    - name: Reconfig AWX (kubernetes) pod after new SSL cert
      shell: kubectl apply -k /root/awx-on-k3s/base --kubeconfig=/etc/rancher/k3s/k3s.yaml
      become: yes

我没有尝试在 AWX pod 内运行 kubectl,只是在服务器上运行。因此,不需要使用 Ansible Kubernetes Core(因为我正在运行 k3s,所以无法使用)。我还尝试使用 Ansibles Raw 和 Command 模块,但都失败了。我还在 AWX“要公开给隔离作业的路径”设置中公开了 kubeconfig 路径。

有人知道为什么它可以直接从 shell 运行文件但通过 Ansible Shell 模块失败吗?

在此先感谢您的帮助。

答案1

我可以通过下载 kubectl 二进制文件、从 dir 路径调用它,然后传递 kubeconfig 文件路径来解决这个问题。

相关内容