Set Empty list with --set-string in ansible for helm upgrade command

6/24/2019

How can I set an empty list in ansible while running helm upgrade command. I am trying to do something like this -

  {% if u.value.args is defined %}
  {% for arg in u.value.args %}
  --set-string apps[{{ loopOut.index0 }}].args[{{ loop.index0 }}]="{{ arg }}"
  {% endfor %}
  {% else %}
  --set-string apps[{{ loop.index0 }}].args=[]
  {% endif %}

In helm template, I am doing something like this -

      {{ $args := len $item.args }}
      {{ if ne 0 $args }}
      args:
      {{ range $arg := $item.args }}
      - {{ $arg }}
      {{ end }}
      {{end}}

But this does not seem to work.Helm complains-

  range can't iterate over [].

How can I solve this?

-- supriya
ansible
ansible-template
kubernetes-helm

0 Answers