Score:1

Ansible shell module fails to find kubectl

cn flag

Running the command from the CLI on the server works perfect, but from playbook using Ansible shell module fails with:

fatal: [localhost]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 127, "stderr": "/bin/sh: kubectl: command not found\n", "stderr_lines": ["/bin/sh: kubectl: command not found"], "stdout": "", "stdout_lines": []}

Playbook task:

    - 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

I am not trying to run kubectl inside the AWX pod, just on the server. Therefore, using Ansible Kubernetes Core is not needed (and can't be used as I am running k3s). I also tried using Ansibles Raw and Command modules, all fail as well. I've also exposed the kubeconfig path in the AWX 'Paths to expose to isolated job' setting.

Anyone have any ideas why it would run file directly from shell but fail through Ansible Shell module?

Thanks in advance for any help.

Score:1
cn flag

I was able to resolve this by downloading the kubectl binary, calling it from the dir path, and then passing the kubeconfig file path.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.