English 中文(简体)
Chef - Blueprints
  • 时间:2024-11-05

Chef - Blueprints


Previous Page Next Page  

In Chef, blueprints are the tools to find out and record exactly what is present on the server. Blueprints record all the things required such as directors, packages, configuration files, and so on. Blueprints have the capabipty to sppt server information in various formats. One of them is Chef recipe. This helps to configure unique server using Chef.

Woring Method

We need to have Python and Git installed on the node where we need to run the blueprint.

Step 1 − Install the blueprint.

vipin@server:~$ pip install blueprint 

Step 2 − Create a blueprint.

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_Raxc3xadz_Certicxc3 
xa1mara_S.A..pem not UTF-8 - skipping it 
# [blueprint] /etc/ssl/certs/NetLock_Arany_=Class_Gold=_Fxc5 
x91tanxc3xbasxc3xadtvxc3xa1ny.pem not UTF-8 - skipping it 
# [blueprint] /etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_Sa 
xc4x9flayxc4xb1cxc4xb1sxc4xb1.pem not UTF-8 - skipping it 
# [blueprint] /etc/ssl/certs/Certinomis_-_Autoritxc3xa9_Racine. 
pem not UTF-8 - skipping it 
# [blueprint] /etc/ssl/certs/Txc3x9cBxc4xb0TAK_UEKAE_Kxc3 
xb6k_Sertifika_Hizmet_Saxc4x9flayxc4xb1cxc4xb1sxc4xb1_-_S 
xc3xbcrxc3xbcm_3.pem not UTF-8 - skipping it 
# [blueprint] searching for APT packages 
# [blueprint] searching for service dependencies

Step 3 − Create a cookbook from the blueprint.

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

Step 4 − Vapdate the content of the generated file.

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

Workflow Script

Blueprint is a Python package that finds out all the relevant configuration data of the server and stores it in a Git repo. Each blueprint has its own name.

One can ask the blueprint to show the content of its Git repo in various formants.

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 

Blueprints Show Commands

user@server:~$ blueprint show-packages my-server 
...TRUNCATED OUTPUT... 
apt wireless-regdb 2011.04.28-1ubuntu3 
apt zpb1g-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 

The preceding command shows all kinds of installed packages. Other show commands are as follows −

    show-files

    show-services

    show-sources

Advertisements