Chef运行期间的AWS OpsWorks Layer

时间:2013-06-12 12:28:32

标签: amazon-web-services chef

我想将自定义JSON传递给我的厨师运行,但显然这只能用于整个堆栈。 我可以使用JSON上的图层名称/ ID和所需的数据,但是如何检查厨师正在努力实施的图层?

2 个答案:

答案 0 :(得分:7)

解决。 SSH连接到我的实例,然后:

sudo opsworks-agent-cli get_json

这显示了与Chef Custom JSON合并的Opsworks JSON ...并且有我的图层名称:

node["opsworks"]["instance"]["layers"][0]

然后我在我的食谱中使用了一些逻辑......

答案 1 :(得分:0)

厨师12:

来自: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