📜  Chef-食谱

📅  最后修改于: 2020-11-04 04:50:14             🧑  作者: Mango


 

Cookbook是Chef的基本工作单元,由与工作单元有关的所有细节组成,具有修改配置和配置为Chef基础结构上的节点的任何系统的状态的功能。食谱可以执行多个任务。食谱包含有关节点所需状态的值。通过使用所需的外部库在Chef中实现。

Chef的关键组成部分

  • 菜谱
  • 元数据
  • 属性
  • 资源资源
  • 范本
  • 图书馆
  • 有助于创建系统的任何其他内容

制作Chef

有两种动态创建食谱的方法。

  • 使用厨师命令
  • 使用刀实用程序

使用Chef命令

要使用Chef命令创建一个空的食谱,请运行以下命令。

C:\Users\vipinkumarm>chef generate cookbook  
C:\Users\vipinkumarm>chef generate cookbook VTest
Installing Cookbook Gems:

Compiling Cookbooks...
Recipe: code_generator::cookbook
   * directory[C:/Users/vipinkumarm/VTest] action create
      - create new directory C:/Users/vipinkumarm/VTest
   
   * template[C:/Users/vipinkumarm/VTest/metadata.rb] action create_if_missing
      - create new file C:/Users/vipinkumarm/VTest/metadata.rb
      - update content in file C:/Users/vipinkumarm/VTest/metadata.rb 
         from none to 4b9435 (diff output suppressed by config)

   * template[C:/Users/vipinkumarm/VTest/README.md] action create_if_missing
      - create new file C:/Users/vipinkumarm/VTest/README.md
      - update content in file C:/Users/vipinkumarm/VTest/README.md 
         from none to 482077 (diff output suppressed by config)

   * cookbook_file[C:/Users/vipinkumarm/VTest/chefignore] action create
      - create new file C:/Users/vipinkumarm/VTest/chefignore
      - update content in file C:/Users/vipinkumarm/VTest/chefignore 
         from none to 15fac5 (diff output suppressed by config)
   
   * cookbook_file[C:/Users/vipinkumarm/VTest/Berksfile] action create_if_missing
      - create new file C:/Users/vipinkumarm/VTest/Berksfile
      - update content in file C:/Users/vipinkumarm/VTest/Berksfile 
         from none to 9f08dc (diff output suppressed by config)

   * template[C:/Users/vipinkumarm/VTest/.kitchen.yml] action create_if_missing
      - create new file C:/Users/vipinkumarm/VTest/.kitchen.yml
      - update content in file C:/Users/vipinkumarm/VTest/.kitchen.yml 
         from none to 93c5bd (diff output suppressed by config)

   * directory[C:/Users/vipinkumarm/VTest/test/integration/default/serverspec]
      action create
      - create new directory
         C:/Users/vipinkumarm/VTest/test/integration/default/serverspec
   
   * directory[C:/Users/vipinkumarm/VTest/test/integration/helpers/serverspec]
      action create
      - create new directory
         C:/Users/vipinkumarm/VTest/test/integration/helpers/serverspec
   
   * cookbook_file
      [C:/Users/vipinkumarm/VTest/test/integration/helpers/serverspec/sp ec_helper.rb]
      action create_if_missing
      - create new file
         C:/Users/vipinkumarm/VTest/test/integration/helpers/serverspec/spec_helper.rb
      - update content in file
         C:/Users/vipinkumarm/VTest/test/integration/helpers/serverspec/spec_helper.rb
         from none to d85df4 (diff output suppressed by config)
   
   * template
      [C:/Users/vipinkumarm/VTest/test/integration/default/serverspec/default _spec.rb]
      action create_if_missing
      - create new file
         C:/Users/vipinkumarm/VTest/test/integration/default/serverspec/default_spec.rb
      - update content in file
         C:/Users/vipinkumarm/VTest/test/integration/default/serverspec/default_spec.rb
         from none to 758b94 (diff output suppressed by config)
   
   * directory[C:/Users/vipinkumarm/VTest/spec/unit/recipes] action create
      - create new directory C:/Users/vipinkumarm/VTest/spec/unit/recipes
   
   * cookbook_file[C:/Users/vipinkumarm/VTest/spec/spec_helper.rb]
      action create_if_missing
      - create new file C:/Users/vipinkumarm/VTest/spec/spec_helper.rb
      - update content in file C:/Users/vipinkumarm/VTest/spec/spec_helper.rb
         from none to 587075 (diff output suppressed by config)

   * template[C:/Users/vipinkumarm/VTest/spec/unit/recipes/default_spec.rb]
      action create_if_missing
      - create new file C:/Users/vipinkumarm/VTest/spec/unit/recipes/default_spec.rb
      - update content in file 
         C:/Users/vipinkumarm/VTest/spec/unit/recipes/default_spec.rb
         from none to 779503 (diff output suppressed by config)
      - create new file C:/Users/vipinkumarm/VTest/recipes/default.rb
      - update content in file C:/Users/vipinkumarm/VTest/recipes/default.rb
         from none to 8cc381 (diff output suppressed by config)

   * cookbook_file[C:/Users/vipinkumarm/VTest/.gitignore] action create
      - create new file C:/Users/vipinkumarm/VTest/.gitignore
      - update content in file C:/Users/vipinkumarm/VTest/.gitignore from none to 33d469
         (diff output suppressed by config)

将在目录中创建名称为VTest的菜谱结构,下面是该结构。

测试

使用刀实用程序

使用以下命令使用美工刀工具创建食谱。

C:\Users\vipinkumarm\VTest>knife cookbook create VTest2 
WARNING: No knife configuration file found 
** Creating cookbook VTest2 in C:/chef/cookbooks 
** Creating README for cookbook: VTest2 
** Creating CHANGELOG for cookbook: VTest2 
** Creating metadata for cookbook: VTest2 

以下是食谱的结构。

食谱