<p>I am trying to deploy a configmap onto a cluster </p>

<pre><code>- name: Make/Update all configmaps on the cluster
 kubernetes:
 api_endpoint: blah
 url_username: blah
 url_password: blah
 inline_data:
 apiVersion: v1
 kind: ConfigMap
 metadata: 
 name: blah
namespace: blah
 data: my-data.txt: "{{ data }}"
 state: present
data: |
 some = foo
 foo = some
(using spinnaker to attach it to pods)
</code></pre>

<p>When I go into the pod and open my-data.txt it displays:</p>

<pre><code>some = foo\n foo = some\n
</code></pre>

<p>I want it to look exactly like the text and print newline rather than \n</p>

<p>Weird thing if I put ' ' single quotes somewhere in the text it prints the text as is but with the single quotes so :</p>

<pre><code>data: |
 some = foo
 foo = some
' '
</code></pre>

<p>prints exactly the same.</p>

<p>I have tried to research but I couldn't find anything and I have been stuck on this for a while now.</p>

<p>This seems to be similar to <a href="https://github.com/kubernetes/kubernetes/issues/36222" rel="noreferrer">kubernetes/kubernetes issue 36222</a> when creating configMap from files.</p>
<p>In your case, that happens when created from a <code>data</code> block.</p>
<p>The recent <a href="https://github.com/kubernetes/kubernetes/issues/63503" rel="noreferrer">kubernetes/kubernetes issue 63503</a> references all printed issues.</p>
<p>A <a href="https://github.com/kubernetes/kubernetes/issues/36222#issuecomment-497132788" rel="noreferrer">comment mentions</a>:</p>
<blockquote>
<p>I added a new line in a configMap using Tab for identation. After changing to Spaces instead of Tab, I was able to see the configmap as expected...</p>
</blockquote>
<p>August 202: The <a href="https://github.com/kubernetes/kubernetes/issues/36222#issuecomment-666168348" rel="noreferrer">issue 36222</a> now includes:</p>
<blockquote>
<p>If you just want the raw output as it was read in when created <code>--from-file</code>, you can use <code>jq</code> to get the raw string (without escaped newlines etc)</p>
<p>If you created a configmap from a file like this:</p>
<pre><code>kubectl create configmap myconfigmap --from-file mydata.txt
</code></pre>
<p>Get the data:</p>
<pre><code>kubectl get cm myconfigmap -o json | jq '.data.&quot;mydata.txt&quot;&quot;' -r
</code></pre>
</blockquote>
<p>Also:</p>
<blockquote>
<p>If the formatting of cm goes wierd a simple hack to get it back to normal is :</p>
<p>kubectl get cm configmap_name -o yaml &gt; cm.yaml</p>
<p>Now copy the contents of <code>cm.yaml</code> file and past it on <a href="http://www.yamllint.com/" rel="noreferrer"><code>yamllint.com</code></a>.  Yamllint.com is powerful tool to check the linting of yaml files.<br />
This will provide you with the configmap as expected with correct formatting.</p>
<p>Paste the output in another yaml file (for e.g - cm_ready.yaml)</p>
<pre><code> kubectl apply -f cm_ready.yaml
</code></pre>
</blockquote>
<hr />
<p>Update Nov. 2020, the <a href="https://github.com/kubernetes/kubernetes/issues/36222#issuecomment-729237587" rel="noreferrer">same issue</a> includes:</p>
<blockquote>
<p>I was able to fix this behavior by:</p>
<ul>
<li><p>Don't use tabs, convert to spaces</p>
</li>
<li><p>To remove spaces before a newline character, use this:</p>
<pre><code>  sed -i -E 's/[[:space:]]+$//g' File.ext
</code></pre>
</li>
</ul>
<p>It seems also will convert CRLF to LF only.</p>
</blockquote>
