# template error while templating string

**URL:** <https://forum.ansible.com/t/template-error-while-templating-string/28628>\
**Category:** Ansible Project\
**Created:** [September 21, 2018, 12:56pm UTC](https://forum.ansible.com/t/template-error-while-templating-string/28628 "2018-09-21T12:56:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narahari\_n\_Savitha](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Narahari\_n\_Savitha](https://forum.ansible.com/u/Narahari_n_Savitha)\
**Post date:** [September 21, 2018, 12:56pm UTC](https://forum.ansible.com/t/template-error-while-templating-string/28628/1 "2018-09-21T12:56:34Z")

</div>

Hello:

Here is the command I am trying to run ansible adhoc

ansible -o APP\_SERVERS\_GROUP[0] -i ~/HOSTS/v2/DATA\_LAB/DIT/DIT1\_DEV/DIT1\_\_LOCAL\_CURR/ -m shell -a “{{ curl -sk localhost:8080/Log4JControl/version.jsp | trim }}” -u ANSIBLE\_USER

The output I get is this

dit1\_dev.cucumber.com | FAILED! =\> {“failed”: true, “msg”: “template error while templating string: expected token ‘end of print statement’, got ‘localhost’. String: {{ curl -sk localhost:8080/Log4JControl/version.jsp | trim }}”}

Is this invalid syntax or am I doing this all wrong ?

All I am trying to avoid is the \r\n chars in the output.

-Narahari

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 21, 2018, 3:25pm UTC](https://forum.ansible.com/t/template-error-while-templating-string/28628/2 "2018-09-21T15:25:56Z")

</div>

> Hello:
> 
> Here is the command I am trying to run ansible adhoc
> 
> ansible -o APP\_SERVERS\_GROUP[0] -i  
> ~/HOSTS/v2/DATA\_LAB/DIT/DIT1\_DEV/DIT1\_\_LOCAL\_CURR/ -m shell -a "{{ curl -sk  
> localhost:8080/Log4JControl/version.jsp | trim }}" -u ANSIBLE\_USER
> 
> The output I get is this
> 
> dit1\_dev.cucumber.com | FAILED! =\> {"failed": true, "msg": "template error  
> while templating string: expected token 'end of print statement', got  
> 'localhost'. String: {{ curl -sk localhost:8080/Log4JControl/version.jsp |  
> trim }}"}
> 
> Is this invalid syntax or am I doing this all wrong ?

In a template(between {{ and }}) you can only use template language call Jinja  
not shell commands.  
[http://jinja.pocoo.org/docs/2.10/templates/](http://jinja.pocoo.org/docs/2.10/templates/)

> All I am trying to avoid is the \r\n chars in the output.

You need to use pure shell command

-a "curl -sk localhost:8080/Log4JControl/version.jsp | tr -d '\r\n'"
