1

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.

BrillCom
  • 139
  • 2
  • 9

1 Answers1

1

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

BrillCom
  • 139
  • 2
  • 9