Dual-Cloud capable chef cookbook

Currently we have a AWS environment that we stand up using Chef. However, we are now looking at adding Azure to the mix to be considered multi-cloud capable for our application teams. Since the original cookbooks were designed for AWS deployment, is there a way inside the cookbook to understand what cloud provider environment its being deployed in (i.e. AWS vs Azure) then switch to the correct attributes type for things like S3 buckets for AWS or Blob for Azure?

env = {
'dev' => 'shared-dev',
'stage' => shared-stage',
'prod' => 'shared-prod',

default['application']['s3-bucket'] = "https://s3.amazonaws.com/#{env[node.chef_environment]}/application-#{node.chef_environment}"

If/else statement to change s3-bucket name if deployed in the Azure cloud environment instead...

default['application']['s3-bucket'] = "StorageAccount.blob.core.windows.net/#{env[node.chef_environment]}/application-#{node.chef_environment}"


Ohai should be pulling in some data about the cloud environment for you, under node['cloud'].

You'll find the platform provider at node['cloud']['provider'], and should come up as 'ec2' or 'azure' for those clouds. If you run ohai from the command line (and probably redirect it into a file for easier reading), you can see the cloud attributes tree.

"cloud": {
"public_ipv4_addrs": [


"local_ipv4_addrs": [


"provider": "ec2",
"public_hostname": "ec2-x-x-x-x.compute-1.amazonaws.com",
"local_hostname": "ip-172-x-x-x.ec2.internal",
"public_ipv4": "x.x.x.x",
"local_ipv4": "172.x.x.x"


Depending on how you want to refactor your cookbooks, you could do a couple of things using the cloud attributes. You could create two sets of attributes with the cloud provider in the structure, or you could be clever and keep the attributes structure you have, but use a case statement:

default['application']['bucket'] = case node['cloud']['provider']
when 'azure'


when 'ec2'



There's an example of this one in the openssh cookbook wrt platforms:


I’ll tack on here, that you can get a specific bit of ohai from the commandline:
> ohai cloud for example (so you don’t have to weed through everything)


Mail](https://go.microsoft.com/fwlink/?LinkId=550986) for Windows 10

Ohai is run as part of every chef-client run, it's included in your install of the chef client software. Chef Infra uses it to get everything from the hostname to IP addresses to the amount of memory your host has. so you don't have to think about it, you can just use what it finds out.

I found one rather complex example of an attributes file, in yum-epel.


honestly, all the attributes files in yum-epel are doing wacky things; there's just no good way to abstract what's going on there.


and there's a couple things in redisio that might suit too


I figured it out via chef-shell. Documentation about ohai and cloud/provider needs a bit of updating.

default['carbonblack']['s3-bucket'] = case node['cloud']['provider']
when 'ec2'
default['carbonblack']['s3-bucket'] = "https://s3.amazonaws.com/core-#{node.chef_environment}/carbonblack"
default['carbonblack']['s3-bucket'] = "https://StorageAccount.blob.core.windows.net/core-#{node.chef_environment}/carbonblack"