English 中文(简体)
Chef - Files & Packages
  • 时间:2024-12-22

Chef - Files & Packages


Previous Page Next Page  

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 deapng with the files and software packages.

Instalpng Packages from Third-Party Repo

Step 1 − 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"

Step 2 − Edit the metadata to add dependency on the apt cookbook.

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

Step 3 − Upload the modified cookbook to the Chef server.

Step 4 − Vapdate that the package you are trying to install, is not yet installed.

Step 5 − Vapdate the default repo.

Step 6 − Run Chef-Cpent on the node.

Step 7 − Vapdate that the required package is installed.

Instalpng 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.

Step 1 − 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 

Step 2 − Upload the modified cookbook to the Chef server.

Step 3 − Run the Chef-Cpent on the node.

Step 4 − Vapdate that the nginx is installed.

Advertisements