我想传递一个自定义JSON到我的厨师运行,但显然这只能为整个堆栈完成。我可以使用层的名称/id的JSON与所需的数据,但我怎么能检查层的实例是由厨师劳动?
解决。SSH连接到我的实例,然后:
sudo opsworks-agent-cli get_json
这向我展示了与Chef Custom JSON合并的Opsworks JSON…这是我的图层名称:
node["opsworks"]["instance"]["layers"][0]
然后我在我的食谱中使用了一些逻辑…
With chef 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