Chef Chef è un framework per l'automazione dell'infrastruttura e la gestione della configurazione scritto in Ruby ed Erlang.
Installazione ed esecuzione autonoma (chef-solo)
Installa il client Chef sui nodi di destinazione usando lo script ufficiale Omnitruck:
# Installa il client Chef
curl -L https://omnitruck.chef.io/install.sh | sudo bash
# Verifica l'installazione
chef-solo -v
Esegui un cookbook autonomo:
chef-solo -c solo.rb -j node.json
Comandi della CLI knife
# Cerca nel registro Supermarket
knife supermarket search mysql
# Scarica l'archivio del cookbook
knife supermarket download nginx
# Inizializza un nodo remoto via SSH
knife bootstrap 192.168.1.50 -x root -P 'password' -N web01
Risorse chiave del DSL per ricette
Pacchetti e servizi
package 'nginx' do
action :install
end
service 'nginx' do
action [:enable, :start]
supports status: true, restart: true, reload: true
end
Download di file remoti
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
Esegui comandi 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' # Guardia: esegui solo se il binario non esiste
end
Guardie condizionali (only_if e 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