Hi I got stuck with one of the scenario, I have two environments Dev and Prod. I need to pass different values in dev and different vales in prod. So how can I manage it using one Data bag. this is my general Data bag in dev environment

I am using this data bag in Dev environment, so I have to pass different username, passwd and jdbc password for prod environment. How can I do this? I am planning to do in below manner

 "id": "some_data_bag_item",
 "production" : {
 "username": "username",
 "passwd": "****",
 "jdbc_password": "****"
  "testing" : {
    "username": "username",
    "passwd": "****",
    "jdbc_password": "****

Is this is a right way? Do we need to add anything else in recipe? Do chef will find out which environment it is automatically?

1 Answer 1



For instance, if a node is in the "production" environment, you could want to run a special recipe in your "nginx" cookbook to bring that server up to production policy requirements. You could also have a recipe in the nginx cookbook meant to configure special changes for testing servers.


name "web_server"
description "A role to configure our front-line web servers"
run_list "recipe[apt]", "recipe[nginx]"
env_run_lists "production" => ["recipe[nginx::config_prod]"], "testing" => ["recipe[nginx::config_test]"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.