Search code examples
ansiblekubernetes-helm

Ansible loop with dict as ansible_loop_var key/value; error `argument 'release_values' is of type <class 'str'> and we were unable to convert to dict`


I'm trying to use the kubernetes.core.helm module in a loop with the following code:

    - name: Install Helm charts
      kubernetes.core.helm:
        name: "{{ item.name }}"
        chart_ref: "{{ item.ref }}"
        namespace: apps
        create_namespace: yes
        wait: yes
        kubeconfig: "{{ kubeconfig.path }}"
        values: "{{ item.values | default(omit) }}"
      loop:
        - name: appA
          ref: repo/appA
          values:
            installCRDs: true
        - name: appB
          ref: "https://<fqdn>/chart_appB.tgz"
        - name: appC
          ref: "https://<fqdn>/chart_appC.tgz"

I'm getting the error (on all 3 iterations): argument 'release_values' is of type <class 'str'> and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value.

How can I make this loop work with the values key passed as an actual dictionary?

I have tried all kinds of different jinja filters, or different syntax's, changed the name of the key values to another, but basically keep getting the same error.

EDIT: I also tried removing default(omit) entirely in combination with the list below, but it made no difference.

      [...]
      loop:
        - name: appA
          ref: repo/appA
          values:
            installCRDs: true
        - name: appB
          ref: "https://<fqdn>/chart_appB.tgz"
          values: ~
        - name: appC
          ref: "https://<fqdn>/chart_appC.tgz"
          values: ~

Solution

  • Turns out it was a combination of wrong syntax of default(omit) and using a reserved keyword (.values being a shorthand for .values()).

    Issue resolved :)