[RESOLVED] A node's chef_organization

I would like to know if there is a way to get a nodes chef_org name. I work in a multitenancy environment and would like to query any given nodes org name.

The org name isn’t set in any config setting you can access, but you can extract it from the URL. Something like this should work:

# => "orgname"

Thanks for the reply. But how could i find the node’s org if I don’t know already? The solution that you present would require me to know the URL (which is tagged by the orgname on the end). The environment I have is multi-tenancy so at times I won’t know ahead of time which node belongs to whom,

I guess I need more context for your question. Do you want to find the org name from within a Chef Client run? If so, the solution I gave will work. You can access the URL from inside a Chef run via Chef::Config.chef_server_url.

I’m new to chef so please excuse my ignorance. But with the example you gave above, I would have to know the URI of the current node correct? And how would I use Chef::Config.chef_server_url? (ie. if statement, puts .etc)


The example I gave is something you could put in a cookbook somewhere to make the cookbook do different things based on what org the Chef Client is in. Chef Client knows the URI of the Chef Server via the config.

If you just want to SSH into a random box and see what org it's in, you can cat or grep the /etc/chef/client.rb file to see the chef_server_url setting.

Sorry for the late reply. That has worked thank you very much.