使用Ansible解析JSON中的单引号



我试图运行一个Ansible剧本,其中有一个JSON的输入单引号在它。剧本运行失败,出现以下错误。有什么方法可以解析单引号吗?到目前为止,我得到低于错误。

JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
expected <block end>, but found '<scalar>'
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
expected <block end>, but found '<scalar>'
The error appears to be in line 161, column 69, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
"logGroups": "aws_log_group_name",
"query": "fields @timestamp, @message | parse @message 'GET *:4' as apiName | parse @message ':443* H' as backend | sort @timestamp desc | stats count() as count by backend | sort count desc"
^ here

JSON:

{
"type": "custom",
"width": 24,
"height": 18,
"properties": {
"params": {
"region": "us-east-1",
"logGroups": "aws_log_group",
"query": "fields @timestamp, @message | parse @message 'GET *:4' as apiName | parse @message ':443* H' as backend | sort @timestamp desc | stats count() as count by backend | sort count desc"
},
"updateOn": {
"refresh": true,
"timeRange": true
},
"title": "ELB logs"
}
}

这是有效的JSON

shell> cat dashboard.json 
{
"type": "custom",
"width": 24,
"height": 18,
"properties": {
"params": {
"region": "us-east-1",
"logGroups": "aws_log_group",
"query": "fields @timestamp, @message | parse @message 'GET *:4' as apiName | parse @message ':443* H' as backend | sort @timestamp desc | stats count() as count by backend | sort count desc"
},
"updateOn": {
"refresh": true,
"timeRange": true
},
"title": "ELB logs"
}
}

和下面的剧本工作如预期

- hosts: localhost
tasks:
- include_vars:
file: dashboard.json
name: dashboard
- debug:
var: dashboard

最新更新