3

我想将自定义 JSON 传递给我的厨师运行,但显然这只能为整个堆栈完成。我可以将 JSON 上的图层名称/ID 与所需数据一起使用,但我如何检查厨师正在处理的实例的图层?

4

2 回答 2

7

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

sudo opsworks-agent-cli get_json

这向我展示了与 Chef Custom JSON 合并的 Opsworks JSON……还有我的图层名称:

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

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

于 2013-06-12T14:33:56.103 回答
2

与厨师 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
于 2017-05-03T01:55:08.797 回答