
- Chef 教程
- Chef - 首頁
- Chef - 概述
- Chef - 架構
- Chef - 版本控制系統設定
- Chef - 工作站設定
- Chef - 客戶端設定
- Chef - Test Kitchen 設定
- Chef - Knife 設定
- Chef - Solo 設定
- Chef - Cookbook
- Chef - Cookbook 依賴
- Chef - 角色
- Chef - 環境
- Chef - Chef-Client 作為守護程序
- Chef - Chef-Shell
- Chef - 測試 Cookbook
- Chef - Foodcritic
- Chef - ChefSpec
- 使用 Test Kitchen 測試 Cookbook
- Chef - 節點
- Chef - Chef-Client 執行
- 高階 Chef
- 動態配置菜譜
- Chef - 模板
- Chef - Chef DSL 中的純 Ruby 程式碼
- Chef - 菜譜中的 Ruby Gems
- Chef - 庫
- Chef - 定義
- Chef - 環境變數
- Chef - 資料包
- Chef - 資料包指令碼
- Chef - 跨平臺 Cookbook
- Chef - 資源
- 輕量級資源提供程式
- Chef - 藍圖
- Chef - 檔案和包
- Chef - 社群 Cookbook
- Chef 有用資源
- Chef - 快速指南
- Chef - 有用資源
- Chef - 討論
Chef - 角色
Chef 中的角色是將節點邏輯分組的一種方法。典型的案例是為 Web 伺服器、資料庫伺服器等設定角色。可以為所有節點設定自定義執行列表,並在角色中覆蓋屬性值。
建立角色
vipin@laptop:~/chef-repo $ subl roles/web_servers.rb name "web_servers" description "This role contains nodes, which act as web servers" run_list "recipe[ntp]" default_attributes 'ntp' => { 'ntpdate' => { 'disable' => true } }
建立角色後,需要將其上傳到 Chef 伺服器。
將角色上傳到 Chef 伺服器
vipin@laptop:~/chef-repo $ knife role from file web_servers.rb
現在,需要將角色分配給名為 server 的節點。
將角色分配給節點
vipin@laptop:~/chef-repo $ knife node edit server "run_list": [ "role[web_servers]" ] Saving updated run_list on node server
執行 Chef-Client
user@server:~$ sudo chef-client ...TRUNCATED OUTPUT... [2013-07-25T13:28:24+00:00] INFO: Run List is [role[web_servers]] [2013-07-25T13:28:24+00:00] INFO: Run List expands to [ntp] ...TRUNCATED OUTPUT...
工作原理
在 Chef 程式碼庫的 roles 資料夾內,使用 Ruby 檔案定義角色。
角色包含名稱和描述屬性。
角色包含特定於角色的執行列表和特定於角色的屬性設定。
執行列表中具有角色的每個節點都將把角色的執行列表提取到自身中。
角色執行列表中的所有菜譜都將在節點上執行。
將使用 knife role from file 命令將角色上傳到 Chef 伺服器。
角色將新增到節點執行列表。
在執行列表中具有角色的節點上執行 Chef 客戶端將執行角色中列出的所有菜譜。
廣告