Chef 文件和包
在 Chef 中,创建配置文件和移动包是关键组件。 Chef 有多种管理方式。 Chef 支持多种方式处理文件和软件包。
从第三方存储库安装软件包
步骤 1-编辑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"
第 2 步-编辑元数据以添加对 apt Cookbook的依赖。
vipin@laptop:~/chef-repo $ subl cookbooks/my_cookbook/metadata.rb
...
depends "apt"
第 3 步-将修改后的Cookbook上传到 Chef 服务器。
第 4 步-验证您尝试安装的软件包尚未安装。
步骤 5-验证默认存储库。
步骤 6-在节点上运行 Chef-Client。
步骤 7-验证是否安装了所需的包。
从源安装软件
如果需要安装一个软件,而该软件在特定平台上无法作为软件包提供,则需要自己编译。在 Chef 中,我们可以通过使用脚本资源来做到这一点。
步骤 1-编辑默认配方。
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
第 2 步-将修改后的Cookbook上传到 Chef 服务器。
步骤 3-在节点上运行 Chef-Client。
步骤 4-验证 nginx 是否已安装。