
Chef Cookbook
By :

Configuration Management is all about configuring your hosts well. Usually, configuration is carried out by using configuration files. Chef's template resource allows you to create these configuration files with dynamic values that are driven by the attributes we've discussed so far in this chapter. You can retrieve dynamic values from data bags and attributes, or even calculate them on-the-fly before passing them into a template.
Make sure you have a cookbook called my_cookbook
and that the run_list
of your node includes my_cookbook
, as described in the Creating and using cookbooks recipe in Chapter 1, Chef Infrastructure.
Let's see how to create and use a template to dynamically generate a file on your node:
Add a template to your recipe:
mma@laptop:~/chef-repo $ subl cookbooks/my_cookbook/recipes/default.rb template '/tmp/message' do source 'message.erb' variables( hi: 'Hallo', world: 'Welt', from: node['fqdn'] ) end
Add the ERB...
Change the font size
Change margin width
Change background colour