Ansible shell not running Helm command

5/3/2020

Is there a way to add the helm repo using ansible? I'm trying to automate it as part of a playbook that bootstraps a cluster, installs helm, and adds the stable repo.

Everything works fine except the add repo bit.

I have this task in my ansible yaml definition

- name: Add helm stable repo
  shell: helm repo add stable https://kubernetes-charts.storage.googleapis.com

But I get the error

"changed": true, "cmd": "helm repo add stable https://kubernetes-charts.storage.googleapis.com/", "/bin/sh: 1: helm: not found" "stderr_lines": ["/bin/sh: 1: helm: not found"]

Which is weird cause helm is definitely installed. I can ssh into the box and run

helm version --short
v3.2.0+ge11b7ce

And when I run

helm repo add stable https://kubernetes-charts.storage.googleapis.com/

directly, it works. But not via ansible.

Any ideas anyone?

-- Tee Hammed
ansible
kubernetes-helm
shell

1 Answer

5/4/2020

Got it to work by doing

- name: Add helm stable repo
  become: yes
  become_user: vagrant
  shell: helm repo add stable {{ helm_stable_repo }}
  args:
    executable: /bin/bash
  register: "results"

- debug:
    var: results

Looks like I just needed to get it to run as the user vagrant.

I added executable: /bin/bash to force it to use /bin/bash Didn't really need to in the end though.

And the debug flag to see the outcome.

-- Tee Hammed
Source: StackOverflow