Template variable Ec2 InstanceID

Greetings Professionals,

I am working on a cookbook ec2config which installs and configure Ec2services , i have created a template where we need to overwrite hostname, ip, fqdn and Ec2InstanceID

i could able to overwrite IP, Hostname, FQDN by declaring the variable as below but couldnot able to pull the instanceID value. Is there any specific attribute provided where i can get the information of InstanceID i have tried all possible ways to get the instanceid but couldnt able to figure it out . Please help

“<%= node[:“ipaddress”] %>” works
"<%= node[:“hostname”] %>" works
"<%= node[:“fqdn”] %>" works
"<%= node[:“InstanceID”] %>" not working

Thanks
Prash

You can use knife to look at all of the data that ohai grabs for your
node. (If you’re using chef server).

You can also just run ohai on your box and grab the output directly.

knife node show NODE_NAME --long will show all of the attributes of a
node. You can use it to look for what you’re looking for.

You can also do knife node show NODE_NAME -a ATTRIBUTE to look at
everything inside of a specific attribute.

In this case, the EC2 info is actually under node.ec2.

For example, my output:

> knife node show galen-testrhel -a ec2
galen-testrhel:
  ec2:
    ...
    instance_id:                 i-##########

https://docs.chef.io/knife_node.html#show

Also useful is search: Allowing you to query the chef server for all the
nodes that match a specific query.
https://docs.chef.io/knife_search.html

@Galen thank you for knife info but i knew about knife -ohai utility where i can pull the information .

But here in my case im trying to overwrite the values in a xml config file where we need to give IP,Hostname,fqdn and InstanceID as inputs i could able to give ip, hostname,fqdn as inputs except InstanceID value of the node

Below is the metrics in which we need to give the dimension name and values as input

{
“Id”: “PerformanceCounter2”,
“FullName”: “AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch”,
“Parameters”: {
“CategoryName”: “Memory”,
“CounterName”: “% Committed Bytes In Use”,
“InstanceName”: “”,
“MetricName”: “MemoryUsed”,
“Unit”: “Percent”,
“DimensionName”: “InstanceId”,
“DimensionValue”: " ",
“DimensionName”: “Ipaddress”,
“DimensionValue” : “xxxxxx”,
“DimensionName”: “hostname”
“DimensionValue”: “xxxxxx”,
“DimensionName”: “fqdn”,
“DimensionValue”: “xxxx”,
}
I believe this info would be more specific to you , please help

Thanks
Prash

Yes,

InstanceID is nested under the EC2 attribute. It's not stored as a top
level like hostname, ipaddress, etc.

This thread shows how to use sub-level attributes: