Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I use templates, databags and environments in chef?

I have templates with variables. these variables are in databags and and depend on the environment. Example:

# Template
address =$foo

# Environment:
develoment

# Databag:
$foo = "sdfsdf"

How do I combine all of that?, I don't know where to put the information.

In template

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

I need to put here a variable

address = $pepe

In my databag in have the following data depending on the environment:

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

I don't know what I should write in the recipe.

like image 264
Marcelino Juarez Valderrama Avatar asked Feb 18 '13 07:02

Marcelino Juarez Valderrama


1 Answers

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
like image 184
Draco Ater Avatar answered Sep 25 '22 13:09

Draco Ater