Problem in passing JSON string in environment to shell module

46 views
Skip to first unread message

Nirav Radia

unread,
Dec 14, 2016, 8:53:29 AM12/14/16
to Ansible Project
I am trying to pass JSON string in environment.

- name: Start {{service_name}}
  shell
: "<<starting springboot jar>> --server.port={{service_port}}\""
  environment
:
   
- SPRING_APPLICATION_JSON: '{"test-host.1":"{{test_host_1}}","test-host.2":"{{test_host_2}}"}'

test_host_1 is 172.31.00.00
test_host_2 is 172.31.00.00

But when in spring logs, I get JSON parse exception where it prints

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character (''' (code 39)): was expecting double-quote to start field name
 at [Source: {'
test-host.1': '172.31.00.00', 'test-host.2': '172.31.00.00'}; line: 1, column: 3]


As seen, double quotes are converted to single quotes !!!

I tried escaping double quotes but with no luck.

Any idea why it happens, or any work around?

Thanks,
Nirav

Kai Stian Olstad

unread,
Dec 14, 2016, 1:48:07 PM12/14/16
to ansible...@googlegroups.com
On 14. des. 2016 14:53, 'Nirav Radia' via Ansible Project wrote:
> I am trying to pass JSON string in environment.
>
> - name: Start {{service_name}}
> shell: "<<starting springboot jar>> --server.port={{service_port}}\""
> environment:
> - SPRING_APPLICATION_JSON:
> '{"test-host.1":"{{test_host_1}}","test-host.2":"{{test_host_2}}"}'

As a workaround you can add a space after the first single quote like this
' {"test-host.1":"{{test_host_1}}","test-host.2":"{{test_host_2}}"}'


> test_host_1 is 172.31.00.00
> test_host_2 is 172.31.00.00
>
> But when in spring logs, I get JSON parse exception where it prints
>
> Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected
> character (''' (code 39)): was expecting double-quote to start field name
> at [Source: {'test-host.1': '172.31.00.00', 'test-host.2': '172.31.00.00'};
> line: 1, column: 3]
>
>
> As seen, double quotes are converted to single quotes !!!
>
> I tried escaping double quotes but with no luck.
>
> Any idea why it happens, or any work around?

No idea why, but it looks like a bug to me.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages