amazon-ec2 - 是否可以在 cloud-config 中使用变量

标签 amazon-ec2 boto cloud-init salt-stack

使用时cloud init's #cloud-config 创建配置文件,我将如何使用变量来填充值?

在我的特定情况下,我想自动启动 EC2 实例作为预配置的 salt minions。 Example of salt minion cloud config

假设我想获取特定的 EC2 实例 ID 并将其设置为 salt minion 的 ID。

我将如何着手为每个实例动态设置值?

最佳答案

在引导命令中 bootcmd可以有环境变量 $INSTANCE_ID ,您可以将其保存以备后用。见 http://cloudinit.readthedocs.org/en/latest/topics/examples.html#run-commands-on-first-boot

例如,我喜欢下面

#cloud-config
bootcmd:
  - echo $INSTANCE_ID > /hello.txt

关于amazon-ec2 - 是否可以在 cloud-config 中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16540730/

相关文章:

amazon-ec2 - 如果代码库更新则更新 CloudFormation 堆栈

ruby-on-rails - SSL rails nginx

python - 使用python + boto删除未使用的AWS安全组,引发vpc错误

javascript - Docker 本地 js 文件 IO 错误

node.js - 在 ec2 node.js 服务器上托管 SSL 证书的位置

python - 给定路径可能存在或不存在的文件列表,如何在 Python 中创建目录?

amazon-s3 - AWS - boto.connect_s3() 在 EC2 实例启动时报告 "No handler was ready to authenticate"

ubuntu - 在 cloud init runcmd 中使用管道失败

amazon-web-services - 在 redhat ec2 实例上找不到/var/log/cloud-init-output.log

amazon-web-services - 如何使 cloud-init 启动脚本在每次 EC2 实例启动时运行?