Chef – Files & Packages

  • Post author:
  • Post category:Chef
  • Post comments:0 Comments

In Chef, creating configuration files and moving packages are the key components. There are multiple ways how Chef manages the same. There are multiple ways how Chef supports in dealing with the files and software packages.

Installing Packages from Third-Party Repo

Step1 − Edit the default recipe of the cookbook.

vipin@laptop:~/chef-repo $ subl cookbooks/test_cookbook/recipes/default.rb 
include_recipe "apt" 
apt_repository "s3tools" do 
   uri "http://s3tools.org/repo/deb-all" 
   components ["stable/"] 
   key "http://s3tools.org/repo/deb-all/stable/s3tools.key" 
   action :add 
end 
package "s3cmd"

Step2 − Edit the metadata to add dependency on the apt cookbook.

vipin@laptop:~/chef-repo $ subl cookbooks/my_cookbook/metadata.rb 
... 
depends "apt"

Step3 − Upload the modified cookbook to the Chef server.

Step4 − Validate that the package you are trying to install, is not yet installed.

Step5 − Validate the default repo.

Step6 − Run Chef-Client on the node.

Step 7 − Validate that the required package is installed.

Installing Software from Source

If one needs to install a piece of software that is not available as a package for a given platform, one needs to compile it oneself. In Chef, we can do this by using the script resource.

Step1 − Edit the default recipe.

vipin@laptop:~/chef-repo $ subl cookbooks/my_cookbook/recipes/ 
default.rb 
version = "1.3.9" 
bash "install_nginx_from_source" do 
   cwd Chef::Config['file_cache_path'] 
   code ≪-EOH 
      wget http://nginx.org/download/nginx-#{version}.tar.gz 
      tar zxf nginx-#{version}.tar.gz && 
      cd nginx-#{version} && 
      ./configure && make && make install 
   EOH 

Step2 − Upload the modified cookbook to the Chef server.

Step3 − Run the Chef-Client on the node.

Step4 − Validate that the nginx is installed.

Leave a Reply