Chef教程
Chef高级

Chef Chef-Shell

编写ChefCookbook总是很困难。由于将它们上传到 Chef 服务器、配置流浪虚拟机、检查它们如何在那里失败、冲洗和重复的反馈周期很长,这使得它变得更加困难。如果我们能在一次完成所有这些繁重的工作之前尝试测试一些片段或Cookbook会更容易。
Chef 带有 Chef-Shell,它本质上是与 Chef 的交互式 Ruby 会话。在 Chef-Shell 中,我们可以创建-
属性 编写Cookbook 初始化 Chef 运行
它用于在将部分Cookbook上传到 Chef 服务器并在节点上执行完整Cookbook之前对其进行即时评估。

运行Shell

步骤 1-在独立模式下运行 Chef-Shell。
mma@laptop:~/chef-repo $ chef-shell 
loading configuration: none (standalone chef-shell session) 
Session type: standalone 
Loading...[2017-01-12T20:48:01+01:00] INFO: Run List is [] 
[2017-01-12T20:48:01+01:00] INFO: Run List expands to [] 
done. 
this is chef-shell, the Chef Shell. 
Chef Version: 11.0.0 
http://www.opscode.com/chef 
http://wiki.opscode.com/display/chef/Home 
run `help' for help, `exit' or ^D to quit. 
Ohai2u mma@laptop!  
chef > 
步骤 2-在 Chef-Shell 中切换到属性模式
Chef > attributes_mode
步骤 3-设置属性值。
chef:attributes > set[:title] = "Chef Cookbook" "ChefCookbook" chef:attributes > 退出 :attributes Chef>
步骤 4-切换到配方模式。
Chef > recipe_mode
步骤 5-创建文件资源。
chef:recipe > file "/tmp/book.txt" do 
chef:recipe > content node.title 
chef:recipe ?> end  
=> <file[/tmp/book.txt] @name: "/tmp/book.txt" @noop: nil @ 
before: nil @params: {} @provider: Chef::Provider::File @allowed_ 
actions: [:nothing, :create, :delete, :touch, :create_if_missing] 
@action: "create" @updated: false @updated_by_last_action: false 
@supports: {} @ignore_failure: false @retries: 0 @retry_delay: 
2 @source_line: "(irb#1):1:in `irb_binding'" @elapsed_time: 0 @ 
resource_name: :file @path: "/tmp/book.txt" @backup: 5 @diff: nil 
@cookbook_name: nil @recipe_name: nil @content: "Chef Cookbook">   
chef:recipe > 
步骤 6-开始运行 Chef 以创建具有给定内容的文件。
chef:recipe > run_chef
[2017-01-12T21:07:49+01:00] INFO: Processing file[/tmp/book.txt] 
action create ((irb#1) line 1) 
---/var/folders/1r/_35fx24d0y5g08qs131c33nw0000gn/T/cheftempfile20121212-
11348-dwp1zs 2012-12-12 21:07:49.000000000 
+0100 
+++ /var/folders/1r/_35fx24d0y5g08qs131c33nw0000gn/T/chefdiff20121212-
11348-hdzcp1 2012-12-12 21:07:49.000000000 +0100 
@@-0,0 +1 @@ 
+Chef Cookbook 
\ No newline at end of file 
[2017-01-12T21:07:49+01:00] INFO: entered create 
[2017-01-12T21:07:49+01:00] INFO: file[/tmp/book.txt] created file 
/tmp/book.txt 

工作原理

Chef-Shell 从交互式 Ruby (IRB) 会话开始,并增强了一些特定功能。 它提供了attributes_mode和interactive_mode等模式。 它有助于编写命令,这些命令写在Cookbook或Cookbook中。 它以交互模式运行所有内容。
我们可以在三种不同的模式下运行 Chef-Shell: 独立模式、客户端模式独奏模式
独立模式-这是默认模式。没有加载任何Cookbook,并且运行列表为空。 客户端模式-在这里,chef-shell 充当Chef客户端。 Solo 模式-在这里,chef-shell 充当 Chef-solo 客户端。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4