<pre><code>kubectl get -n istio-system secret istio-ca -ogo-template='{{index .data &quot;tls.crt&quot;}}' | base64 -d &gt; ca.pem
</code></pre>
<p>how to run the above command in an ansible playbook?</p>
<p>I am trying to use it as follows:</p>
<pre><code>- name: Apply secret istio-ca
  shell: kubectl get -n istio-system secret istio-ca -ogo-template='{{index .data &quot;tls.crt&quot;}}' | base64 -d &gt; ca.pem
  register: sout
</code></pre>
<p>but this gives me an error as follows:</p>
<pre><code>fatal: [172.31.20.135]: FAILED! =&gt; {&quot;msg&quot;: &quot;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 \&quot;tls.crt\&quot;}}' | base64 -d &gt; ca.pem&quot;}
</code></pre>

Dhananjay Gahiwade
<p>I swear this has been answered a thousand times, but I can't immediately find the golang/helm/kubectl specific one in the <a href="https://stackoverflow.com/search?q=%5Bansible%5D+end+of+print+statement">thousands of this same error</a></p>
<p>The problem is that jinja2 uses <code>{{</code> as its escape syntax, but golang text templating uses <code>{{</code> 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</p>
<p>There are two paths out of that situation: <a href="https://jinja.palletsprojects.com/en/3.0.x/templates/#escaping" rel="noreferrer"><code>{% raw %}</code> and <code>{% endraw %}</code></a> or having an outer jinja2 expression that resolves to the inner golang expression</p>
<pre class="lang-yaml prettyprint-override"><code>- debug:
    msg: kubectl get {% raw %}-ogo-template={{ awesome }}{% endraw %}
- debug:
    msg: kubectl get -ogo-template={{&quot;{{&quot;}} awesome {{&quot;}}&quot;}}
</code></pre>
