Answers: <p><a href="https://www.digitalocean.com/community/tutorials/how-to-use-roles-and-environments-in-chef-to-control-server-configurations" rel="nofollow noreferrer">https://www.digitalocean.com/community/tutorials/how-to-use-roles-and-environments-in-chef-to-control-server-configurations</a></p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>Example</p>
  
  <blockquote>
  <pre><code>name "web_server"
  description "A role to configure our front-line web servers"
  run_list "recipe[apt]", "recipe[nginx]"
  env_run_lists "production" =&gt; ["recipe[nginx::config_prod]"], "testing" =&gt; ["recipe[nginx::config_test]"]
  </code></pre>
  </blockquote>
  
Answers: CC BY-SA 3.0
Answers: 2017-08-25T21:49:16.340Z
Answers: 2017-08-25T21:49:16.340Z
Answers: 030
Body: <p>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</p>
  
  <p>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</p>
  
  <pre><code>{
   "id": "some_data_bag_item",
   "production" : {
   "id":"Databag_item",
   "username": "username",
   "passwd": "****",
   "jdbc_password": "****"
  }
   },
    "testing" : {
      "id":"Databag_item",
      "username": "username",
      "passwd": "****",
      "jdbc_password": "****
    }
   }
  </code></pre>
  
  <p>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?</p>
  
Tags: <chef>
Title: Managing Data bags in different environments
UserDisplayName: pandey
ThreadText: # Managing Data bags in different environments
  
  (Asked by: username_0 on 2017-08-25)
  
  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" : {
   "id":"Databag_item",
   "username": "username",
   "passwd": "****",
   "jdbc_password": "****"
  }
   },
    "testing" : {
      "id":"Databag_item",
      "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?
  
  **Tags:** chef
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-08-25. Score: 3
  
  <https://www.digitalocean.com/community/tutorials/how-to-use-roles-and-environments-in-chef-to-control-server-configurations>
  
  > 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.
  
  Example
  
  > ```
  > 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]"]
  >
  > ```
  
  
  ---
  
  