Template file adding new line in the output in hashicorp agent with kubernates

Following

once the template file generated in the target pod using the template in configmap:
template {
destination = “/tmp/keyfiledir/keyfile”
contents = <<EOT
{{- with secret “secret/data/myapp/config” }}
{{ .Data.data.username }}={{ .Data.data.password }}
{{ end }}
EOT
}

the outputfile is something like below:
cat keyfile

appuser=a secret phrase…

Here i am having two newlines above and below which i do not want in my case.
As i need to put some secret only and read that with something in my framework.
Please let me know if there is some way to remove the before and after new lines.

Actually i want the ouput for cat something like:

cat keyfile
appuser=a secret phrase…

Please help.
Seems there is something like trimspace function for something similar.
Please help me how i can use it in above template.

I can not test it right now, but should be something like

{{- with secret “secret/data/myapp/config” }}
{{- .Data.data.username }}={{ .Data.data.password }}
{{- end }}

https://golang.org/pkg/text/template/
“Text and spaces”…

The one i am going to try is
template {
destination = “/tmp/keyfiledir/keyfile”
contents = <<EOT
{{- with secret “secret/data/myapp/config” }}
{{- .Data.data.username }}={{ .Data.data.password }}
{{- end }}
EOT
}
Will let you now.

Cannot Thanks more …seems working.

1 Like

This is not totally resolved.
i am storing base64 encoded value of ‘a secret phrase…’ which comes to be ‘YSBzZWNyZXQgcGhyYXNlLi4u’
this value is further used to some decryption …now that decreption is failing.
the decreption is failing probably due to wrong fetch by vault-agent.
on cat of file i am getting value ‘YSBzZWNyZXQgcGhyYXNlLi4u’ which is visibelly correct. but length is coming out to be 25 which is incorrect as length of ‘YSBzZWNyZXQgcGhyYXNlLi4u’ 24.There is seeming to be one extra line feed at the end to retrieved text.
cat -A keyfile is showing, keyfile is here the retrieved file.
a secret phrase…$
Output shall be
a secret phrase…