[英]AWS OpsWorks Layer during Chef run
I want to pass a custom JSON to my chef run, but apparently this only can be done for the entire stack. 我想将自定义JSON传递给我的厨师运行,但显然这只能用于整个堆栈。 I could use the layers name/id on the JSON with the desired data, but how can i check the layer which the instace is being labored by chef? 我可以使用JSON上的图层名称/ ID和所需的数据,但是我如何检查厨师正在努力实施的图层?
Solved. 解决了。 SSH connect to my instance, then : SSH连接到我的实例,然后:
sudo opsworks-agent-cli get_json
This shows me the Opsworks JSON that is merged with Chef Custom JSON... and there is my layer's name: 这向我展示了与Chef Custom JSON合并的Opsworks JSON ......并且有我的图层名称:
node["opsworks"]["instance"]["layers"][0]
Then i used some logic in my recipe... 然后我在我的食谱中使用了一些逻辑......
With chef 12: 有厨师12:
from: https://forums.aws.amazon.com/thread.jspa?threadID=190405 来自: https : //forums.aws.amazon.com/thread.jspa?threadID = 190405
node_instance = search(:node, "hostname:#
{node['hostname'].upcase}").first
Chef::Log.info "This is an instance object as returned by Chef Server.
EC2 Instance ID is #{node_instance['ec2']['instance_id']}"
aws_instance = search(:aws_opsworks_instance, "hostname:#
{node['hostname'].upcase}").first
Chef::Log.info "This is the AWS OpsWorks instance object. It has AWS
OpsWorks specific attributes, like the Layer IDs for the instance: #
{aws_instance['layer_ids'].join(',')}"
aws_instance['layer_ids'].each do |layer_id|
layer = search(:aws_opsworks_layer, "layer_id:#{layer_id}").first
Chef::Log.info "The instance belongs to layer #{layer['layer_id']},
it's name is #{layer['name']}"
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.