How I use templates, databags and environments in chef?
Asked Answered
D

1

5

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.

Draft answered 18/2, 2013 at 7:22 Comment(1)
could you please be more precise?Shayshaya
V
11

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
Valenciavalenciennes answered 18/2, 2013 at 11:29 Comment(1)
Thanks this is a need, you are the bestDraft

© 2022 - 2024 — McMap. All rights reserved.