gpt4 book ai didi

amazon-ec2 - 用于 EC2 Image Builder 的 yaml 中的多行 bash 脚本

转载 作者:行者123 更新时间:2023-12-04 15:18:00 27 4
gpt4 key购买 nike

我正在尝试创建自定义组件文档。虽然我已经使用各种 yaml linters 测试了 yaml 文件,但 EC2 Image builder 提示以下错误

Failed to create component. Fix the error(s) and try again:
The value supplied for parameter 'data' is not valid. Parsing step 'ConfigureMySQL' in phase 'build' failed. Error: line 4: cannot unmarshal map into string.
我无法弄清楚我的 yaml 文件有什么问题
name: MyJavaAppTestDocument
description: This is JavaApp Document
schemaVersion: 1.0

phases:
- name: build
steps:
- name: InstallSoftware
action: ExecuteBash
inputs:
commands:
- sudo yum update -y
- sudo yum install -y java-1.8.0
- sudo amazon-linux-extras install -y tomcat8.5
- sudo yum install -y https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
- sudo yum install -y mysql-community-server

- name: ConfigureTomcat
action: ExecuteBash
inputs:
commands:
- sudo sed -i 's/<\/tomcat-users>/\n<role rolename="manager-gui"\/>\n <role
rolename="manager-script"\/>\n <role rolename="admin-gui"\/>\n <user username="admin"
password="admin" roles="manager-gui,manager-script,admin-gui"\/>\n<\/tomcat-users>/'
/etc/tomcat/tomcat-users.xml
- sudo systemctl start tomcat
- sudo systemctl enable tomcat

- name: ConfigureMySQL
action: ExecuteBash
inputs:
commands:
- sudo systemctl start mysqld
- sudo systemctl enable mysqld
- mysqlpass=$(sudo grep 'temporary password' /var/log/mysqld.log | sed 's/.*root@localhost: //')
- mysql -u root -p$mysqlpass --connect-expired-password -h localhost -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'whyDoTh1s@2020'"
- |
sudo cat <<EoF > /tmp/mysql-create-user.sql
CREATE USER 'admin'@'%' IDENTIFIED BY 'whyDoTh1s@2020';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
EoF

- sudo mysql -u root -pwhyDoTh1s@2020 -h localhost < /tmp/mysql-create-user.sql
感谢有人能帮我找到错误。目标是使用预配置的软件和设置构建 AMI。

最佳答案

由于 :,您收到该错误在这一行:

- mysqlpass=$(sudo grep 'temporary password' /var/log/mysqld.log | sed 's/.*root@localhost: //')
YAML 解析器将该行解释为创建映射,而不是在现有映射中创建字符串条目。我能够在我自己的 YAML 中使用的解决方法是包围 :用单引号,所以问题行会变成
- mysqlpass=$(sudo grep 'temporary password' /var/log/mysqld.log | sed 's/.*root@localhost':' //')
据本人使用和 this online YAML parser我使用该解决方案进行了测试,应该可以解决问题。

关于amazon-ec2 - 用于 EC2 Image Builder 的 yaml 中的多行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63980045/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com