得到;无法分析YAML错误“;将JSON转换为yml时
我使用格式。它很好用 但检查的结果是无效的YAML 错误之一:得到;无法分析YAML错误“;将JSON转换为yml时,json,yaml,converter,pyyaml,Json,Yaml,Converter,Pyyaml,我使用格式。它很好用 但检查的结果是无效的YAML 错误之一: Error: Unable to parse. Line: 36 - Ref: ALIYUN::StackId 请帮助我将JSON转换为有效的YML。谢谢 我的JSON文件: { "ROSTemplateFormatVersion": "2015-09-01", "Resources": { "k8s_node_cloudinit_wait_cond": { "Type": "ALIYUN::RO
Error: Unable to parse.
Line: 36 - Ref: ALIYUN::StackId
请帮助我将JSON转换为有效的YML。谢谢
我的JSON文件:
{
"ROSTemplateFormatVersion": "2015-09-01",
"Resources": {
"k8s_node_cloudinit_wait_cond": {
"Type": "ALIYUN::ROS::WaitCondition",
"Properties": {
"Count": "1",
"Handle": {
"Ref": "k8s_node_cloudinit_wait_cond_handle"
},
"Timeout": 1000
}
},
"k8s_sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"SecurityGroupIngress": [
{
"Priority": 1,
"IpProtocol": "all",
"NicType": "internet",
"SourceCidrIp": "0.0.0.0/0",
"PortRange": "-1/-1"
}
],
"VpcId": {
"Ref": "k8s_vpc"
},
"SecurityGroupEgress": [
{
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "internet",
"PortRange": "-1/-1"
}
],
"SecurityGroupName": "k8s_sg"
}
},
"SubAccount": {
"Type": "ALIYUN::RAM::User",
"Properties": {
"UserName": {
"Fn::Join": [
"",
[
"SubAccount",
{
"Ref": "ALIYUN::StackId"
}
]
]
}
}
},
"k8s_node_cloudinit_wait_cond_handle": {
"Type": "ALIYUN::ROS::WaitConditionHandle"
},
"ECSManagePolicy": {
"Type": "ALIYUN::RAM::ManagedPolicy",
"Properties": {
"PolicyName": {
"Fn::Join": [
"",
[
"ECSManagePolicy",
{
"Ref": "ALIYUN::StackId"
}
]
]
},
"PolicyDocument": {
"Version": "1",
"Statement": [
{
"Action": [
"*"
],
"Resource": [
"*"
],
"Effect": "Allow"
},
{
"Action": [
"vpc:DescribeVpcs",
"vpc:DescribeVSwitches"
],
"Resource": [
"*"
],
"Effect": "Allow"
}
]
},
"Users": [
{
"Fn::GetAtt": [
"SubAccount",
"UserName"
]
}
]
}
},
"AccessKey": {
"Type": "ALIYUN::RAM::AccessKey",
"Properties": {
"UserName": {
"Fn::GetAtt": [
"SubAccount",
"UserName"
]
}
}
},
"k8s_master": {
"Type": "ALIYUN::ECS::Instance",
"Properties": {
"UserData": {
"Fn::Replace": [
{
"ros-notify": {
"Fn::GetAtt": [
"k8s_master_cloudinit_wait_cond_handle",
"CurlCli"
]
}
},
{
"Fn::Join": [
"",
[
"#!/bin/sh\n",
"until yum -y install expect || ! cat /etc/os-release|grep centos; do echo 'wait yum ready ...'; sleep 1; done\n",
"curl -sSL http://aliacs-k8s.oss-cn-hangzhou.aliyuncs.com/installer/kubemgr-1.7.2.sh | ",
"bash -s nice --node-type master --oss-region ap-southeast-1 --key-id ",
{
"Fn::GetAtt": [
"AccessKey",
"AccessKeyId"
]
},
" --key-secret ",
{
"Fn::GetAtt": [
"AccessKey",
"AccessKeySecret"
]
},
"\n",
"TOKEN=`kubeadm token list | grep token |awk '{print $1}'`\n",
"ros-notify -d \"{\\\"data\\\": \\\"$TOKEN\\\"}\" \n"
]
]
}
]
},
"SystemDiskCategory": "cloud_ssd",
"VpcId": {
"Ref": "k8s_vpc"
},
"SecurityGroupId": {
"Ref": "k8s_sg"
},
"ImageId": "centos_7",
"VSwitchId": {
"Ref": "k8s_vswitch"
},
"IoOptimized": "optimized",
"Password": "abcABC@147896325",
"InstanceType": "ecs.n1.medium",
"PrivateIpAddress": "192.168.0.1"
}
},
"k8s_vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "k8s_vpc"
},
"CidrBlock": "192.168.0.0/16",
"ZoneId": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": {
"Ref": "ALIYUN::Region"
}
}
]
}
}
},
"k8s_master_cloudinit_wait_cond": {
"Type": "ALIYUN::ROS::WaitCondition",
"Properties": {
"Count": 1,
"Handle": {
"Ref": "k8s_master_cloudinit_wait_cond_handle"
},
"Timeout": 900
}
},
"k8s_nodes": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"UserData": {
"Fn::Replace": [
{
"ros-notify": {
"Fn::GetAtt": [
"k8s_node_cloudinit_wait_cond_handle",
"CurlCli"
]
}
},
{
"Fn::Join": [
"",
[
"#!/bin/sh\n",
"until yum -y install expect || ! cat /etc/os-release|grep centos; do echo 'wait yum ready ...'; sleep 1; done\n",
"export TOKEN=`echo '",
{
"Fn::GetAtt": [
"k8s_master_cloudinit_wait_cond",
"Data"
]
},
"' | awk -F '\"' '{print $4}'`\n",
"curl -sSL http://aliacs-k8s.oss-cn-hangzhou.aliyuncs.com/installer/kubemgr-1.7.2.sh | ",
"bash -s nice --node-type node --oss-region ap-southeast-1 --key-id ",
{
"Fn::GetAtt": [
"AccessKey",
"AccessKeyId"
]
},
" --key-secret ",
{
"Fn::GetAtt": [
"AccessKey",
"AccessKeySecret"
]
},
" --token $TOKEN ",
" --endpoint 192.168.0.1:6443\n",
"num=$(cat /dev/urandom | head -n 10 | cksum | awk -F ' ' '{print $1}')\n",
"seconds=$(($num%30))\n",
"sleep $seconds\n",
"ros-notify -d \"{\\\"data\\\": \\\"$TOKEN\\\"}\" \n"
]
]
}
]
},
"SystemDiskCategory": "cloud_ssd",
"VpcId": {
"Ref": "k8s_vpc"
},
"MinAmount": "1",
"SecurityGroupId": {
"Ref": "k8s_sg"
},
"ImageId": "centos_7",
"VSwitchId": {
"Ref": "k8s_vswitch"
},
"IoOptimized": "optimized",
"Password": "abcABC@147896325",
"InstanceType": "ecs.n1.medium",
"MaxAmount": "1"
}
},
"k8s_master_cloudinit_wait_cond_handle": {
"Type": "ALIYUN::ROS::WaitConditionHandle"
},
"k8s_vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"VpcName": "k8s_vpc",
"CidrBlock": "192.168.0.0/16"
}
}
},
"Outputs": {
"k8s_master_token": {
"Value": {
"Fn::GetAtt": [
"k8s_master_cloudinit_wait_cond",
"Data"
]
}
},
"DashboardURL": {
"Description": "Kubernetes dashboard URL.",
"Value": {
"Fn::Join": [
"",
[
"http://",
{
"Fn::GetAtt": [
"k8s_master",
"PublicIp"
]
},
":80"
]
]
}
},
"k8s_node_token": {
"Value": {
"Fn::GetAtt": [
"k8s_node_cloudinit_wait_cond",
"Data"
]
}
}
}
}
您不应该使用该验证器,它声称是最好的,但它实际上并不符合YAML 1.2或YAML 1.1 其投诉的YAML线(36)为: 断开的验证器无法处理的事情之一是未加引号的标量字符串中的冒号(即
ALIYUN::StackId
)。由于冒号后面没有空格,或者(在YAML 1.2中)前面和后面没有双引号,从不表示键值对,因此不会与有效的YAML混淆
只要尝试在PyYAML中加载转换的输出,或者将其粘贴到站点(基于PyYAML),您就会发现没有问题。虽然PyYAML也不是完美的(并且只支持大多数YAML 1.1),但这是一个比您一直使用的站点好得多的验证。您不应该使用该验证程序,它声称是最好的,但它实际上并不符合YAML 1.2或YAML 1.1 其投诉的YAML线(36)为: 断开的验证器无法处理的事情之一是未加引号的标量字符串中的冒号(即
ALIYUN::StackId
)。由于冒号后面没有空格,或者(在YAML 1.2中)前面和后面没有双引号,从不表示键值对,因此不会与有效的YAML混淆
只要尝试在PyYAML中加载转换的输出,或者将其粘贴到站点(基于PyYAML),您就会发现没有问题。虽然PyYAML也不完美(并且只支持大部分YAML 1.1),但这是一个比您一直使用的站点更好的验证。我使用JSON转换为YML,它工作得很好。我使用JSON转换为YML,它工作得很好。谢谢您的回答。我使用YAML模板与阿里云ROS合作,未通过验证。因此,我必须验证模板。还有什么建议吗?谢谢你的回答。我使用YAML模板与阿里云ROS合作,未通过验证。因此,我必须验证模板。还有什么建议吗?
- Ref: ALIYUN::StackId