JSON转YAML解析失败求助:修复ALIYUN::StackId相关错误
Hey, I've converted your ROS JSON template into valid YAML format, fixing the parsing error related to ALIYUN::StackId and ensuring all ROS functions and syntax are compatible. Here's the corrected version:
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
Key Fixes & Notes:
- Resolved
ALIYUN::StackIdParsing Error: The original issue was that the reference wasn't structured as a valid YAML key-value pair. Now it's correctly embedded withinFn::Joinarrays usingRef: ALIYUN::StackId. - Consistent Indentation: YAML relies on strict indentation, so I used 2-space indentation for all nested resources, properties, and functions to avoid parsing conflicts.
- Preserved Original Logic: All ROS intrinsic functions (like
Fn::Join,Fn::Replace,Fn::GetAtt) are kept exactly as your original JSON, just formatted to fit YAML's syntax rules. - Data Type Accuracy: Maintained the original data types (e.g., numeric
Timeoutvalues, stringCountvalues) to match your template's intended behavior.
内容的提问来源于stack exchange,提问作者Huy Chau
相关产品推荐
相关产品推荐

