相关疑难解决方法(0)

Ansible - 将环境中的JSON字符串传递给shell模块

我试图在环境中传递JSON字符串.

- 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}}"}'
Run Code Online (Sandbox Code Playgroud)

test_host_1是172.31.00.00

test_host_2是172.31.00.00

但是在spring日志中,我会在打印时获得JSON解析异常

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]
Run Code Online (Sandbox Code Playgroud)

如图所示,双引号转换为单引号!

我试图逃避双引号但没有运气.

知道为什么会这样,或者任何解决方法吗?

json ansible

4
推荐指数
2
解决办法
5196
查看次数

标签 统计

ansible ×1

json ×1