Skip to content

Instantly share code, notes, and snippets.

@tfitch
Created March 18, 2015 20:20
Show Gist options
  • Save tfitch/f9ca2d2194d1cd4f968a to your computer and use it in GitHub Desktop.
Save tfitch/f9ca2d2194d1cd4f968a to your computer and use it in GitHub Desktop.
Chef data bags with environments
# the key here is line 4 where the node.chef_environment will match an element of the JSON
keyfile_bag = Chef::EncryptedDataBagItem.load("mongodb", "keyfiles")
file '/apps/mongodb-linux-x86_64-2.4.8/conf/mongodb.key' do
content keyfile_bag[node.chef_environment]['keyfile']
owner 'mongo'
group 'mongo'
mode 00700
action :create_if_missing
end
{
"id": "keyfiles",
"production" : {
"keyfile" : "GaZvLzM0AB1gQ"
},
"stage" : {
"keyfile" : "mXlB1LmSqj3nq"
},
"load": {
"keyfile" : "Aoua2K2OfdTSi"
},
"localhost" : {
"keyfile" : "tkhTjuydq8PJS"
},
"_default" : {
"keyfile" : "h34kwGTNoPFoU"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment