How do I use templates, databases and environments in a chef?

I have templates with variables. these variables are in databases and are environmentally dependent. Example:

# Template
address =$foo

# Environment:
develoment

# Databag:
$foo = "sdfsdf"

How do I combine all this? I do not know where to put the information.

In the template

address = "Http://ffff/dfg/"

I need to put a variable here

address = $pepe

My database has the following data depending on the environment:

 $pepe = "Http://ffff/dfg/"
 $pepep ="Http://ffff/dewrwerw/

I do not know what I should write in the recipe.

+5
source share
1 answer

Template:

address = <%= @pepe %>

Databag:

{
  "_default": {
    "pepe": "Http://ffff/dfg/"
  },
  "staging": {
    "pepe": "Http://ffff/staging"
  },
  "production": {
    "pepe": "Http://ffff/prod"
  }
}

Recipe:

data = data_bag_item( 'databagname', 'itemname' )

template '/path/to/file' do
  variables( pepe: data[node.chef_environment]['pepe'] )
end
+9
source

All Articles