【发布时间】:2023-01-18 15:37:46
【问题描述】:
我有一个自动安装 wordpress 的 terraform 脚本。 terraform 脚本运行良好,但问题出在用户数据上。我想将 wp-config.php 文件中的 localhost 条目替换为 rds 数据库实例 ID。我将文件作为用户数据传递。这是我正在使用的代码。
rds=$(aws rds --region us-east-2 describe-db-instances --query "DBInstances[*].Endpoint.Address" --output text)
cd /var/www/html
cp wp-config-sample.php wp-config.php
sed -i "s/database_name_here/WPTestDevRDS/g" wp-config.php
sed -i "s/username_here/admin/g" wp-config.php
sed -i "s/password_here/Adminhere1234/g" wp-config.php
sed -i "s/localhost/$rds/g" wp-config.php
用户数据正在执行,但问题是我无法将 localhost 的值替换为 $rds 的值。 localhost 条目已删除,但未分配变量 $rds 的值。我也曾尝试在 sed 中使用${rds},但它没有用。在这种情况下的任何帮助表示赞赏。
我期待 $rds 而不是 localhost 的值。 wp-config.php 文件的示例外观
define( 'DB_NAME', 'WPTestDevRDS' );^M
^M
/** Database username */^M
define( 'DB_USER', 'admin' );^M
^M
/** Database password */^M
define( 'DB_PASSWORD', 'Adminhere1234' );^M
^M
/** Database hostname */^M
define( 'DB_HOST', 'localhost' );^M //i need to replace localhost with the value of $rds
【问题讨论】:
标签: linux bash amazon-web-services