Solvedansible "template error while templating string: Missing end of comment tag" error
✔️Accepted Answer
EDIT:
- When unsafe characters are defined in vars, follow @inossidabile's recommendation to use !unsafe.
- When unsafe characters are expressed directly in templates themselves, you can use
{% raw %} ... {% endraw %}
as shown below.
I found that this solution from Ric in the 'Template problem with bash array length syntax' thread solved this for my needs. Final output can still produce {#
without it being interpreted as the beginning of a jinja2 comment.
Example solution in templates:
{% raw %}
APPLICATION=${app:13:`expr ${#app} - 1 - 13`}
"vmxconfigchecksum": "_6{#<\bo]qk\u0005~L",
{% endraw %}
Example solution in jinja2-powered yaml:
wordpress_salts: |
{% raw %}
define('AUTH_KEY', 'pNiI@l*NXAp6y&0/Pz7QpVH3Z@3o(NnCv(sO6/54ob=a-eo3Xzkezc6s#f)`O6VL');
define('SECURE_AUTH_KEY', '.tJ7^utC-NG>(DhKLr:5T+rYq@]MLU-H-/|g{A,4T4RM(>%ELpkVpE!q<JH+=Rr)');
define('LOGGED_IN_KEY', 'mj43;u[G+=e)uy|i%D{oT[G&NZ}]nyeBA$ra{*r!&3uH8p|.~GJXg1M!qX}?e{9+');
define('NONCE_KEY', 'e-TBw_;,qQ<eHv#UEDI@+b#rz.yjZp=]iH@|h1CWAxQAE_:Pv@}>+9AA.N!;qc3=');
define('AUTH_SALT', 'H}Hc,Bh-e+s9E6/1-wfP|?6ge-a{#k8Nskvb6d~Im*|<+E=bRVFrB*4Lx %Som/B');
define('SECURE_AUTH_SALT', '01s`J:i0U=/yQ{unA==C?f|NO/ >Sj~$cKD/X#t(lsNkN?vo/(cH/z(7dih+)F,|');
define('LOGGED_IN_SALT', ';Zg YlE4Z)<+op5.>k|J7%Z>{+ZT4qnoTuU/E^j::[L>.tkxEE-d*yCur}lP8{!6');
define('NONCE_SALT', '1r{tDqj?Vl}Nx^yB+XYWo~}*[k8&ndG2aX,sB^;:osQk[?;DAoXDhN)+fZcx}=Wf');
{% endraw %}
Other Answers:
Looks like {#
needs to be escaped in your file.
@VRODRIGUES You can avoid escaping by doing something like this:
APPLICATION=${app:13:$(($(expr length "$app") - 1 - 13))}
I just ran into this in a multiline yml string in host_vars
on 2.1.1.0
.
The randomly generated output from https://api.wordpress.org/secret-key/1.1/salt/ contained {#
.
- wordpress_version: "4.5"
wordpress_salts: |
define('AUTH_KEY', 'pNiI@l*NXAp6y&0/Pz7QpVH3Z@3o(NnCv(sO6/54ob=a-eo3Xzkezc6s#f)`O6VL');
define('SECURE_AUTH_KEY', '.tJ7^utC-NG>(DhKLr:5T+rYq@]MLU-H-/|g{A,4T4RM(>%ELpkVpE!q<JH+=Rr)');
define('LOGGED_IN_KEY', 'mj43;u[G+=e)uy|i%D{oT[G&NZ}]nyeBA$ra{*r!&3uH8p|.~GJXg1M!qX}?e{9+');
define('NONCE_KEY', 'e-TBw_;,qQ<eHv#UEDI@+b#rz.yjZp=]iH@|h1CWAxQAE_:Pv@}>+9AA.N!;qc3=');
define('AUTH_SALT', 'H}Hc,Bh-e+s9E6/1-wfP|?6ge-a{#k8Nskvb6d~Im*|<+E=bRVFrB*4Lx %Som/B');
define('SECURE_AUTH_SALT', '01s`J:i0U=/yQ{unA==C?f|NO/ >Sj~$cKD/X#t(lsNkN?vo/(cH/z(7dih+)F,|');
define('LOGGED_IN_SALT', ';Zg YlE4Z)<+op5.>k|J7%Z>{+ZT4qnoTuU/E^j::[L>.tkxEE-d*yCur}lP8{!6');
define('NONCE_SALT', '1r{tDqj?Vl}Nx^yB+XYWo~}*[k8&ndG2aX,sB^;:osQk[?;DAoXDhN)+fZcx}=Wf');
Downgrading to 1.9.6
or replacing {#
resolves the error.
Hi,
I also have problem with bash
script as well. #!/usr/bin/env bash
then got error said AnsibleError: template error while templating string: Missing end of comment tag
ISSUE TYPE
Bug Report
COMPONENT NAME
core
ANSIBLE VERSION
2.1.0.0
CONFIGURATION
OS / ENVIRONMENT
SUMMARY
I'm getting the above error in v2.1.0.0 calling
debug
module below.The shell command is using cloudformation-ruby-dsl gem to generate a cloudformation template. The error was picked up when using the
template
module but can be reproduced by merely usingdebug
as above.This error does not occur with v2.0.1.0. I have reverted back to this version and verified that the error does not occur.
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS