Chef Chef es un framework de automatización de infraestructura y gestión de configuraciones escrito en Ruby y Erlang.
Instalación y ejecución independiente con chef-solo
Instale el cliente Chef en los nodos de destino mediante el script oficial de Omnitruck:
# Instalar cliente de Chef
curl -L https://omnitruck.chef.io/install.sh | sudo bash
# Verificar instalación
chef-solo -v
Ejecutar un cookbook independiente:
chef-solo -c solo.rb -j node.json
Comandos de la CLI knife
# Buscar en el registro Supermarket
knife supermarket search mysql
# Descargar paquete de cookbook
knife supermarket download nginx
# Inicializar nodo remoto mediante SSH
knife bootstrap 192.168.1.50 -x root -P 'password' -N web01
Recursos clave del DSL de recetas
Paquetes y servicios
package 'nginx' do
action :install
end
service 'nginx' do
action [:enable, :start]
supports status: true, restart: true, reload: true
end
Descarga de archivos remotos
remote_file '/usr/local/src/node.tar.gz' do
source 'https://nodejs.org/dist/v18.0.0/node-v18.0.0.tar.gz'
checksum 'sha256checksumhere...'
mode '0644'
action :create_if_missing
end
Ejecutar comandos de shell
execute 'compile_app' do
command './configure && make && make install'
cwd '/usr/local/src/app'
environment 'PATH' => "/usr/local/bin:#{ENV['PATH']}"
creates '/usr/local/bin/app' # Guard: ejecutar solo si el archivo binario no existe
end
Guardias condicionales (only_if y not_if)
execute 'migrate_database' do
command 'rails db:migrate'
cwd '/var/www/app/current'
only_if { File.exist?('/var/www/app/current/Rakefile') }
not_if 'pg_isready -h localhost'
end