简体   繁体   English

在Chef配方中获取EC2实例名称

[英]Getting EC2 instance name inside a Chef recipe

How can I dynamically capture the ec2 instance name on which my Chef recipe is running? 如何动态捕获运行Chef Chef配方的ec2实例名称?

@coderanger I am using below code @coderanger我正在使用下面的代码

Ohai.plugin(:EC2) do 
provides "ec2" 
depends "ec2" collect_data do 
instance_id = ec2['instance_id'] 
end 
end 

How to print the instance id here ? 如何在这里打印实例ID?

Assuming you mean the EC2 instance ID, you can find it in node['ec2']['instance_id'] if the EC2 ohai plugin has been activated. 假设您的意思是EC2实例ID,如果EC2 ohai插件已被激活,您可以在node['ec2']['instance_id']找到它。 If the instance is created via knife ec2 server create this is done automatically for you, and there is an imperfect auto-enable that tries to guess if you're on EC2. 如果实例是通过knife ec2 server create这将自动为您完成,并且有一个不完美的自动启用试图猜测您是否在EC2上。 If neither of these are the case, you can force it by creating an empty file in /etc/chef/ohai/hints/ec2.json . 如果这两种情况都不是这样,您可以通过在/etc/chef/ohai/hints/ec2.json创建一个空文件来强制它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM