# Template lookup formatting JSON to be passed on to shell module

**URL:** <https://forum.ansible.com/t/template-lookup-formatting-json-to-be-passed-on-to-shell-module/28092>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 19, 2018, 1:08pm UTC](https://forum.ansible.com/t/template-lookup-formatting-json-to-be-passed-on-to-shell-module/28092 "2018-07-19T13:08:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bozho](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bozho/32/10430_2.png) [@bozho](https://forum.ansible.com/u/bozho)\
**Post date:** [July 19, 2018, 1:08pm UTC](https://forum.ansible.com/t/template-lookup-formatting-json-to-be-passed-on-to-shell-module/28092/1 "2018-07-19T13:08:14Z")

</div>

Hi all,

I've lost the entire day on this and got nowhere...

I have a JSON file parameter that needs to be passed to aws CLI utility as a  
file, and I'm trying to avoid creating temp files using bash here files.

Basically, I want to pass this to the shell module:

"bash -c 'aws s3api put-bucket-replication --profile {{ aws\_profile }}  
--bucket {{ vault\_bucket\_name }} --replication-configuration file://\<(echo {{  
lookup('template', 'this\_is\_my\_template.json.j2') }})'"

with the lookup returning a single-line JSON string with double quotes.

I've tried using convert\_data=false in the lookup, I've tried string and  
to\_json filters. I've tried adding a leading space at the beginning of the  
template file, nothing worked.

I either get a string where fields are wrapped in u'', or I get escaped  
newlines and double quotes that confuse bash. I've tried doing replace on the  
resulting templated string, but it's very hard to see what's the actual string  
being passed to the shell module, as any ansible output is JSON, so it gets  
escaped back 🙂

Thank you,
