Reputation: 359
kubectl get -n istio-system secret istio-ca -ogo-template='{{index .data "tls.crt"}}' | base64 -d > ca.pem
how to run the above command in an ansible playbook?
I am trying to use it as follows:
- name: Apply secret istio-ca
shell: kubectl get -n istio-system secret istio-ca -ogo-template='{{index .data "tls.crt"}}' | base64 -d > ca.pem
register: sout
but this gives me an error as follows:
fatal: [172.31.20.135]: FAILED! => {"msg": "template error while templating string: expected token 'end of print statement', got 'string'. String: kubectl get -n istio-system secret istio-ca -ogo-template='{{index .data \"tls.crt\"}}' | base64 -d > ca.pem"}
Upvotes: 0
Views: 4182
Reputation: 33203
I swear this has been answered a thousand times, but I can't immediately find the golang/helm/kubectl specific one in the thousands of this same error
The problem is that jinja2 uses {{
as its escape syntax, but golang text templating uses {{
as its escape syntax, and because ansible does not know you mean the golang version, it tried to evaluate your go-template as if it was jinja2 and kaboom
There are two paths out of that situation: {% raw %}
and {% endraw %}
or having an outer jinja2 expression that resolves to the inner golang expression
- debug:
msg: kubectl get {% raw %}-ogo-template={{ awesome }}{% endraw %}
- debug:
msg: kubectl get -ogo-template={{"{{"}} awesome {{"}}"}}
Upvotes: 5