简体   繁体   中英

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. 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?

Solved. SSH connect to my instance, then :

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:

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

Then i used some logic in my recipe...

With chef 12:

from: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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