Chef cookbook编写


创建cookbook(workstation执行)

# 1.创建 first_cookbook
cd /opt/chef-data/chef-repo/cookbooks
chef generate cookbook first_cookbook


# 2.编写
vim first_cookbook/recipes/default.rb
# 内容如下:(执行 `ip a` 将其结果写到 `/root/ifconfig.txt`文件中 )

  

execute 'repo_ifconfig' do
  command 'ip a >> /root/ifconfig.txt'
  ignore_failure true
end

上传cookbook(workstation执行)

# 1.上传cookbook至Chef Server
cd /opt/chef-data/chef-repo/cookbooks
knife cookbook upload first_cookbook
# 2.查看cookbook列表 
knife cookbook list

 

 添加cookbook到目标节点(workstation执行)

cd /opt/chef-data/chef-repo/cookbooks
knife node run_list add node4 first_cookbook

执行cookbook(node4执行)

chef-client

验证结果(node4执行)

# 1.查看ifconfig.txt文件是否生成
ls /root
# 2.查看ifconfig.txt内容
cat /root/ifconfig.txt

猜你喜欢

转载自www.cnblogs.com/yuxiaohao/p/12325105.html