template error while templating string

22 views
Skip to first unread message

Narahari 'n' Savitha

unread,
Sep 21, 2018, 8:56:34 AM9/21/18
to Ansible Project
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

Kai Stian Olstad

unread,
Sep 21, 2018, 11:26:11 AM9/21/18
to ansible...@googlegroups.com
On Friday, 21 September 2018 14.56.34 CEST Narahari 'n' Savitha wrote:
> 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/

> 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'"

--
Kai Stian Olstad


Reply all
Reply to author
Forward
0 new messages