Chef - 藍圖



在 Chef 中,藍圖是用於查詢和記錄伺服器上現有內容的工具。藍圖記錄所有必需的內容,例如目錄、包、配置檔案等等。藍圖能夠以多種格式拆分伺服器資訊,其中一種是 Chef 菜譜。這有助於使用 Chef 配置唯一的伺服器。

工作方法

我們需要在需要執行藍圖的節點上安裝 Python 和 Git。

步驟 1 - 安裝藍圖。

vipin@server:~$ pip install blueprint 

步驟 2 - 建立藍圖。

user@server:~$ sudo blueprint create internal-cookbook 
# [blueprint] using cached blueprintignore(5) rules 
# [blueprint] searching for Python packages 
# [blueprint] searching for PEAR/PECL packages 
# [blueprint] searching for Yum packages 
# [blueprint] searching for Ruby gems 
# [blueprint] searching for npm packages 
# [blueprint] searching for software built from source 
# [blueprint] searching for configuration files 
# [blueprint] /etc/ssl/certs/AC_Ra\xc3\xadz_Certic\xc3\ 
xa1mara_S.A..pem not UTF-8 - skipping it 
# [blueprint] /etc/ssl/certs/NetLock_Arany_=Class_Gold=_F\xc5\ 
x91tan\xc3\xbas\xc3\xadtv\xc3\xa1ny.pem not UTF-8 - skipping it 
# [blueprint] /etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_Sa\ 
xc4\x9flay\xc4\xb1c\xc4\xb1s\xc4\xb1.pem not UTF-8 - skipping it 
# [blueprint] /etc/ssl/certs/Certinomis_-_Autorit\xc3\xa9_Racine. 
pem not UTF-8 - skipping it 
# [blueprint] /etc/ssl/certs/T\xc3\x9cB\xc4\xb0TAK_UEKAE_K\xc3\ 
xb6k_Sertifika_Hizmet_Sa\xc4\x9flay\xc4\xb1c\xc4\xb1s\xc4\xb1_-_S\ 
xc3\xbcr\xc3\xbcm_3.pem not UTF-8 - skipping it 
# [blueprint] searching for APT packages 
# [blueprint] searching for service dependencies

步驟 3 - 從藍圖建立 Cookbook。

user@server:~$ blueprint show -C internal-cookbook my-server/recipes/default.rb

步驟 4 - 驗證生成的 檔案內容。

user@server:~$ cat internal-cookbook /recipes/default.rb 
# 
# Automatically generated by blueprint(7). Edit at your own risk. 
# 
cookbook_file('/tmp/96468fd1cc36927a027045b223c61065de6bc575.tar') 
do 
   backup false 
   group 'root' 
   mode '0644' 
   owner 'root' 
   source 'tmp/96468fd1cc36927a027045b223c61065de6bc575.tar' 
end 
execute('/tmp/96468fd1cc36927a027045b223c61065de6bc575.tar') do 
   command 'tar xf "/tmp/96468fd1cc36927a027045b223c61065de6bc575.tar"' 
   cwd '/usr/local' 
end 
directory('/etc/apt/apt.conf.d') do 
...TRUNCATED OUTPUT... 
service('ssh') do 
   action [:enable, :start] 
   subscribes :restart, resources('cookbook_file[/etc/default/ 
      keyboard]', 'cookbook_file[/etc/default/console-setup]', 
      'cookbook_file[/etc/default/ntfs-3g]', 'package[openssh-server]', 
      'execute[96468fd1cc36927a027045b223c61065de6bc575.tar]') 
end

工作流程指令碼

藍圖是一個 Python 包,它查詢伺服器的所有相關配置資料並將其儲存在 Git 倉庫中。每個藍圖都有自己的名稱。

使用者可以要求藍圖以各種格式顯示其 Git 倉庫的內容。

user@server:~$ ls -l internal-cookbook / 
total 8 
drwxrwxr-x 3 vagrant vagrant 4096 Jun 28 06:01 files 
-rw-rw-r-- 1 vagrant vagrant 0 Jun 28 06:01 metadata.rb 
drwxrwxr-x 2 vagrant vagrant 4096 Jun 28 06:01 recipes 

藍圖顯示命令

user@server:~$ blueprint show-packages my-server 
...TRUNCATED OUTPUT... 
apt wireless-regdb 2011.04.28-1ubuntu3 
apt zlib1g-dev 1:1.2.3.4.dfsg-3ubuntu4 
python2.7 distribute 0.6.45 
python2.7 pip 1.3.1 
pip blueprint 3.4.2 
pip virtualenv 1.9.1 

上述命令顯示所有已安裝的包。其他顯示命令如下:

  • show-files
  • show-services
  • show-sources
廣告
© . All rights reserved.